diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index b3f18eee38..64304b7070 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -1368,7 +1368,7 @@ function remove_accents( $string ) { */ function sanitize_file_name( $filename ) { $filename_raw = $filename; - $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0)); + $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", "%", "+", chr(0)); /** * Filter the list of characters to remove from a filename. * diff --git a/tests/phpunit/tests/formatting/SanitizeFileName.php b/tests/phpunit/tests/formatting/SanitizeFileName.php index 727ed7e341..8927fec774 100644 --- a/tests/phpunit/tests/formatting/SanitizeFileName.php +++ b/tests/phpunit/tests/formatting/SanitizeFileName.php @@ -11,7 +11,7 @@ class Tests_Formatting_SanitizeFileName extends WP_UnitTestCase { } function test_removes_special_chars() { - $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0)); + $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", "%", "+", chr(0)); $string = 'test'; foreach ( $special_chars as $char ) $string .= $char; @@ -26,10 +26,10 @@ class Tests_Formatting_SanitizeFileName extends WP_UnitTestCase { */ function test_replace_spaces() { $urls = array( - 'unencoded space.png' => 'unencoded-space.png', - 'encoded%20space.jpg' => 'encoded-space.jpg', - 'plus+space.jpg' => 'plus-space.jpg', - 'multi %20 +space.png' => 'multi-space.png', + 'unencoded space.png' => 'unencoded-space.png', + 'encoded-space.jpg' => 'encoded-space.jpg', + 'plus+space.jpg' => 'plusspace.jpg', + 'multi %20 +space.png' => 'multi-20-space.png', ); foreach( $urls as $test => $expected ) { @@ -49,4 +49,11 @@ class Tests_Formatting_SanitizeFileName extends WP_UnitTestCase { $this->assertEquals("a-t", sanitize_file_name("a t")); $this->assertEquals("a-t", sanitize_file_name("a \n\n\nt")); } + + /** + * @ticket 16226 + */ + function test_replaces_percent_sign() { + $this->assertEquals( 'a22b.jpg', sanitize_file_name( 'a%22b.jpg' ) ); + } }