From 101d00601e8d00041218e31194c6f5e0dc4940aa Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 24 Jul 2020 18:03:02 +0000 Subject: [PATCH] Media: Remove accents in `sanitize_file_name()`. This brings some consistency with `sanitize_title()` and `sanitize_user()`. Props tar.gz, NumidWasNotAvailable, juliobox, p_enrique, cristovaov, zodiac1978, mikeschroder, markoheijnen, chriscct7, swissspidy, DrProtocols, pento, gitlost, joemcgill, dustinbolton, programmin, Vayu, MaximeCulea, lucasbustamante, nilovelez, RavanH, audrasjb, SergeyBiryukov. See #22363. Built from https://develop.svn.wordpress.org/trunk@48603 git-svn-id: http://core.svn.wordpress.org/trunk@48365 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 15 ++++++++++----- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index a85f14f014..d031656d43 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -1984,7 +1984,9 @@ function remove_accents( $string ) { * @return string The sanitized filename. */ function sanitize_file_name( $filename ) { - $filename_raw = $filename; + $filename_raw = $filename; + $filename = remove_accents( $filename ); + $special_chars = array( '?', '[', ']', '/', '\\', '=', '<', '>', ':', ';', ',', "'", '"', '&', '$', '#', '*', '(', ')', '|', '~', '`', '!', '{', '}', '%', '+', '’', '«', '»', '”', '“', chr( 0 ) ); // Check for support for utf8 in the installed PCRE library once and store the result in a static. @@ -2013,10 +2015,11 @@ function sanitize_file_name( $filename ) { * @param string $filename_raw The original filename to be sanitized. */ $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw ); - $filename = str_replace( $special_chars, '', $filename ); - $filename = str_replace( array( '%20', '+' ), '-', $filename ); - $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename ); - $filename = trim( $filename, '.-_' ); + + $filename = str_replace( $special_chars, '', $filename ); + $filename = str_replace( array( '%20', '+' ), '-', $filename ); + $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename ); + $filename = trim( $filename, '.-_' ); if ( false === strpos( $filename, '.' ) ) { $mime_types = wp_get_mime_types(); @@ -2068,7 +2071,9 @@ function sanitize_file_name( $filename ) { } } } + $filename .= '.' . $extension; + /** This filter is documented in wp-includes/formatting.php */ return apply_filters( 'sanitize_file_name', $filename, $filename_raw ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index ed0d0641de..330420d561 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-beta3-48602'; +$wp_version = '5.5-beta3-48603'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.