Make WordPress Core


Ignore:
Timestamp:
07/01/2025 03:38:44 PM (7 months ago)
Author:
dmsnell
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/sanitizeFileName.php

    r55209 r60399  
    3636     *
    3737     * @ticket 16330
     38     * @ticket 62995
    3839     */
    3940    public function test_replaces_spaces() {
    4041        $urls = array(
    41             'unencoded space.png'  => 'unencoded-space.png',
    42             'encoded-space.jpg'    => 'encoded-space.jpg',
    43             'plus+space.jpg'       => 'plusspace.jpg',
    44             'multi %20 +space.png' => 'multi-20-space.png',
     42            'unencoded space.png'                         => 'unencoded-space.png',
     43            'encoded-space.jpg'                           => 'encoded-space.jpg',
     44            'plus+space.jpg'                              => 'plusspace.jpg',
     45            'multi %20 +space.png'                        => 'multi-20-space.png',
     46            "Screenshot 2025-02-19 at 2.17.33\u{202F}PM.png" => 'Screenshot-2025-02-19-at-2.17.33-PM.png',
     47            "Filename with non-breaking\u{00A0}space.txt" => 'Filename-with-non-breaking-space.txt',
     48            "Filename with thin\u{2009}space.txt"         => 'Filename-with-thin-space.txt',
    4549        );
    4650
Note: See TracChangeset for help on using the changeset viewer.