Make WordPress Core

Ticket #16330: 16330.6.diff

File 16330.6.diff, 2.1 KB (added by ericmann, 11 years ago)

Refresh patch, add multiple unit test cases.

  • src/wp-admin/includes/file.php

     
    471471
    472472        $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
    473473
    474         // Strip the query strings.
    475         $filename = str_replace('?','-', $filename);
    476         $filename = str_replace('&','-', $filename);
    477 
    478474        // Move the file to the uploads dir
    479475        $new_file = $uploads['path'] . "/$filename";
    480476        if ( false === @ rename( $file['tmp_name'], $new_file ) ) {
  • src/wp-includes/formatting.php

     
    10491049        $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw );
    10501050        $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
    10511051        $filename = str_replace($special_chars, '', $filename);
     1052        $filename = str_replace( array( '%20', '+' ), '-', $filename );
    10521053        $filename = preg_replace('/[\s-]+/', '-', $filename);
    10531054        $filename = trim($filename, '.-_');
    10541055
  • tests/phpunit/tests/formatting/SanitizeFileName.php

     
    1919                $this->assertEquals( 'testtest', sanitize_file_name( $string ) );
    2020        }
    2121
     22        /**
     23         * Test that spaces are correctly replaced with dashes.
     24         *
     25         * @ticket 16330
     26         */
     27        function test_replace_spaces() {
     28                $urls = array(
     29                        'unencoded space.png'   => 'unencoded-space.png',
     30                        'encoded%20space.jpg'   => 'encoded-space.jpg',
     31                        'plus+space.jpg'        => 'plus-space.jpg',
     32                        'multi %20 +space.png'   => 'multi-space.png',
     33                );
     34
     35                foreach( $urls as $test => $expected ) {
     36                        $this->assertEquals( $expected, sanitize_file_name( $test ) );
     37                }
     38        }
     39
    2240        function test_replaces_any_number_of_hyphens_with_one_hyphen() {
    2341                $this->assertEquals("a-t-t", sanitize_file_name("a----t----t"));
    2442        }