WordPress.org

Make WordPress Core


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

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

Props: xknown, peterwilsoncc.

File:
1 edited

Legend:

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

    r46586 r47638  
    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.