Ticket #16330: 16330.6.diff
File 16330.6.diff, 2.1 KB (added by , 11 years ago) |
---|
-
src/wp-admin/includes/file.php
471 471 472 472 $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); 473 473 474 // Strip the query strings.475 $filename = str_replace('?','-', $filename);476 $filename = str_replace('&','-', $filename);477 478 474 // Move the file to the uploads dir 479 475 $new_file = $uploads['path'] . "/$filename"; 480 476 if ( false === @ rename( $file['tmp_name'], $new_file ) ) { -
src/wp-includes/formatting.php
1049 1049 $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw ); 1050 1050 $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename ); 1051 1051 $filename = str_replace($special_chars, '', $filename); 1052 $filename = str_replace( array( '%20', '+' ), '-', $filename ); 1052 1053 $filename = preg_replace('/[\s-]+/', '-', $filename); 1053 1054 $filename = trim($filename, '.-_'); 1054 1055 -
tests/phpunit/tests/formatting/SanitizeFileName.php
19 19 $this->assertEquals( 'testtest', sanitize_file_name( $string ) ); 20 20 } 21 21 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 22 40 function test_replaces_any_number_of_hyphens_with_one_hyphen() { 23 41 $this->assertEquals("a-t-t", sanitize_file_name("a----t----t")); 24 42 }