WordPress.org

Make WordPress Core

Changeset 29290


Ignore:
Timestamp:
07/24/2014 10:08:09 PM (5 years ago)
Author:
wonderboymusic
Message:

In sanitize_file_name(), replace %20 and + with dashes. Remove unnecessary code from _wp_handle_upload().

Adds unit tests.

Props ericmann.
Fixes #16330.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/file.php

    r29209 r29290  
    328328
    329329    $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
    330     // Strip the query strings.
    331     $filename = str_replace( '?', '-', $filename );
    332     $filename = str_replace( '&', '-', $filename );
    333330
    334331    // Move the file to the uploads dir.
  • trunk/src/wp-includes/formatting.php

    r29163 r29290  
    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, '.-_');
  • trunk/tests/phpunit/tests/formatting/SanitizeFileName.php

    r25002 r29290  
    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"));
Note: See TracChangeset for help on using the changeset viewer.