Commit 83e4ec848d for wordpress.org
commit 83e4ec848dbd580a06698e901d5ac75810bccbfc
Author: dmsnell <dmsnell@git.wordpress.org>
Date: Tue Jul 1 15:40:28 2025 +0000
sanitize_file_name(): Normalize all space characters to a space.
The `sanitize_file_name()` function normalizes the no-break space to a normal space (U+0020) in order to prevent issues saving files with the no-break space in it.
This patch expands the replacement to all space characters, since it’s known that macOS stores a NARROW NO-BREAK SPACE (U+202F) in screenshot filenames between the time and the am/pm indicator.
There are deeper issues with the way this function works, but this patch resolves a known and common problem without raising any of the deeper refactoring questions.
Developed in https://github.com/wordpress/wordpress-develop/pull/9103
Discussed in https://core.trac.wordpress.org/ticket/62995
Props audrasjb, desrosj, dmsnell, jonsurrell, matt, room34, siliconforks, zieladam.
Fixes #62995.
Built from https://develop.svn.wordpress.org/trunk@60399
git-svn-id: http://core.svn.wordpress.org/trunk@59735 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php
index 4033571edf..234d71a2a1 100644
--- a/wp-includes/formatting.php
+++ b/wp-includes/formatting.php
@@ -2035,7 +2035,17 @@ function sanitize_file_name( $filename ) {
}
if ( $utf8_pcre ) {
- $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
+ /**
+ * Replace all whitespace characters with a basic space (U+0020).
+ *
+ * The “Zs” in the pattern selects characters in the `Space_Separator`
+ * category, which is what Unicode considers space characters.
+ *
+ * @see https://www.unicode.org/reports/tr44/#General_Category_Values
+ * @see https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-6/#G17548
+ * @see https://www.php.net/manual/en/regexp.reference.unicode.php
+ */
+ $filename = preg_replace( '#\p{Zs}#siu', ' ', $filename );
}
/**
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 935d131183..1e7121e38f 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '6.9-alpha-60398';
+$wp_version = '6.9-alpha-60399';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.