WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/29/2020 03:52:19 PM (18 months ago)
Author:
whyisjake
Message:

Formatting: Expand sanitize_file_name to have better support for utf8 characters.

Brings the changes in [47638] to the 5.4 branch.

Props: xknown, peterwilsoncc.

Location:
branches/5.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.4

  • branches/5.4/tests/phpunit/tests/formatting/SanitizeFileName.php

    r46586 r47643  
    6969        $this->assertEquals( 'no-extension', sanitize_file_name( '_.no-extension' ) );
    7070    }
     71
     72    /**
     73     * @dataProvider data_wp_filenames
     74     */
     75    function test_replaces_invalid_utf8_characters( $input, $expected ) {
     76        $this->assertEquals( $expected, sanitize_file_name( $input ) );
     77    }
     78
     79    function data_wp_filenames() {
     80        return array(
     81            [ urldecode( '%B1myfile.png' ), 'myfile.png' ],
     82            [ urldecode( '%B1myfile' ), 'myfile' ],
     83            [ 'demo bar.png', 'demo-bar.png' ],
     84            [ 'demo' . json_decode( '"\u00a0"' ) . 'bar.png', 'demo-bar.png' ],
     85        );
     86    }
    7187}
Note: See TracChangeset for help on using the changeset viewer.