From a9661d650cc2199eb31fee4e6867c0607f97aafb Mon Sep 17 00:00:00 2001 From: dmsnell Date: Sun, 31 Aug 2025 06:05:30 +0000 Subject: [PATCH] Formatting: Rely on _wp_can_use_pcre_u() to detect UTF-8 PCRE support. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- wp-includes/formatting.php | 9 +-------- wp-includes/version.php | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 72fcb4e554..b6bf168de2 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -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). * diff --git a/wp-includes/version.php b/wp-includes/version.php index 5489863251..ce229cb071 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.