Make WordPress Core

Ticket #16330: 16330.5.diff

File 16330.5.diff, 2.0 KB (added by mattheu, 9 years ago)
  • src/wp-admin/includes/file.php

    diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php
    index 8cbe242..917ccef 100644
    a b function wp_handle_sideload( &$file, $overrides = false, $time = null ) { 
    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

    diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
    index 77ecbcd..b0768dd 100644
    a b function sanitize_file_name( $filename ) { 
    10211021        $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw );
    10221022        $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
    10231023        $filename = str_replace($special_chars, '', $filename);
     1024        $filename = str_replace( array( '%20', '+' ), '-', $filename);
    10241025        $filename = preg_replace('/[\s-]+/', '-', $filename);
    10251026        $filename = trim($filename, '.-_');
    10261027
  • tests/phpunit/tests/formatting/SanitizeFileName.php

    diff --git a/tests/phpunit/tests/formatting/SanitizeFileName.php b/tests/phpunit/tests/formatting/SanitizeFileName.php
    index e4f0824..2668275 100644
    a b class Tests_Formatting_SanitizeFileName extends WP_UnitTestCase { 
    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                $string = "test %20+test -test";
     29                $this->assertEquals( 'test-test-test', sanitize_file_name( $string ) );
     30        }
     31
    2232        function test_replaces_any_number_of_hyphens_with_one_hyphen() {
    2333                $this->assertEquals("a-t-t", sanitize_file_name("a----t----t"));
    2434        }