Formatting: Rely on _wp_can_use_pcre_u() to detect UTF-8 PCRE support.

The `sanitize_file_name()` function attempts to detect UTF-8 PCRE support, but WordPress already provides a more robust method. It then caches its check in a static var, which WordPress already does in the canonical function `_wp_can_use_pcre_u()`.

This patch refactors `sanitize_file_name()` to call `_wp_can_use_pcre_u()` directly instead of (mostly) recreating and recaching Core’s detection algorithm.

Developed in https://github.com/WordPress/wordpress-develop/pull/9678
Discussed in https://core.trac.wordpress.org/ticket/63863

Follow-up to [60694].

Props dmsnell.
See #63863.

Built from https://develop.svn.wordpress.org/trunk@60695


git-svn-id: http://core.svn.wordpress.org/trunk@60031 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dmsnell
2025-08-31 06:05:30 +00:00
parent 5fa2d232eb
commit a9661d650c
2 changed files with 2 additions and 9 deletions

View File

@@ -2195,20 +2195,13 @@ function sanitize_file_name( $filename ) {
$special_chars = array( '?', '[', ']', '/', '\\', '=', '<', '>', ':', ';', ',', "'", '"', '&', '$', '#', '*', '(', ')', '|', '~', '`', '!', '{', '}', '%', '+', '', '«', '»', '”', '“', chr( 0 ) );
// Check for support for utf8 in the installed PCRE library once and store the result in a static.
static $utf8_pcre = null;
if ( ! isset( $utf8_pcre ) ) {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$utf8_pcre = @preg_match( '/^./u', 'a' );
}
if ( ! wp_is_valid_utf8( $filename ) ) {
$_ext = pathinfo( $filename, PATHINFO_EXTENSION );
$_name = pathinfo( $filename, PATHINFO_FILENAME );
$filename = sanitize_title_with_dashes( $_name ) . '.' . $_ext;
}
if ( $utf8_pcre ) {
if ( _wp_can_use_pcre_u() ) {
/**
* Replace all whitespace characters with a basic space (U+0020).
*

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.9-alpha-60694';
$wp_version = '6.9-alpha-60695';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.