Skip to content

Commit c70e3d6

Browse files
committed
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 #9678 Discussed in https://core.trac.wordpress.org/ticket/63863 Follow-up to [60694]. Props dmsnell. See #63863. git-svn-id: https://develop.svn.wordpress.org/trunk@60695 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6b006e9 commit c70e3d6

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

src/wp-includes/formatting.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,20 +2195,13 @@ function sanitize_file_name( $filename ) {
21952195

21962196
$special_chars = array( '?', '[', ']', '/', '\\', '=', '<', '>', ':', ';', ',', "'", '"', '&', '$', '#', '*', '(', ')', '|', '~', '`', '!', '{', '}', '%', '+', '', '«', '»', '', '', chr( 0 ) );
21972197

2198-
// Check for support for utf8 in the installed PCRE library once and store the result in a static.
2199-
static $utf8_pcre = null;
2200-
if ( ! isset( $utf8_pcre ) ) {
2201-
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
2202-
$utf8_pcre = @preg_match( '/^./u', 'a' );
2203-
}
2204-
22052198
if ( ! wp_is_valid_utf8( $filename ) ) {
22062199
$_ext = pathinfo( $filename, PATHINFO_EXTENSION );
22072200
$_name = pathinfo( $filename, PATHINFO_FILENAME );
22082201
$filename = sanitize_title_with_dashes( $_name ) . '.' . $_ext;
22092202
}
22102203

2211-
if ( $utf8_pcre ) {
2204+
if ( _wp_can_use_pcre_u() ) {
22122205
/**
22132206
* Replace all whitespace characters with a basic space (U+0020).
22142207
*

0 commit comments

Comments
 (0)