diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
index 4f632ee..403b2ce 100644
|
|
function remove_accents( $string ) { |
1725 | 1725 | * operating systems and special characters requiring special escaping |
1726 | 1726 | * to manipulate at the command line. Replaces spaces and consecutive |
1727 | 1727 | * dashes with a single dash. Trims period, dash and underscore from beginning |
1728 | | * and end of filename. |
| 1728 | * and end of filename. It is not guaranteed that this function will return a |
| 1729 | * filename that is allowed to be uploaded. |
1729 | 1730 | * |
1730 | 1731 | * @since 2.1.0 |
1731 | 1732 | * |
… |
… |
function sanitize_file_name( $filename ) { |
1750 | 1751 | $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename ); |
1751 | 1752 | $filename = trim( $filename, '.-_' ); |
1752 | 1753 | |
| 1754 | if ( false === strpos( $filename, '.' ) ) { |
| 1755 | $filetype = wp_check_filetype( 'test.' . $filename ); |
| 1756 | if ( $filetype['ext'] === $filename ) { |
| 1757 | $filename = 'unnamed-file.' . $filetype['ext']; |
| 1758 | } else { |
| 1759 | $filename .= $filetype['ext']; |
| 1760 | } |
| 1761 | } |
| 1762 | |
1753 | 1763 | // Split the filename into a base and extension[s] |
1754 | 1764 | $parts = explode('.', $filename); |
1755 | 1765 | |
diff --git tests/phpunit/tests/formatting/SanitizeFileName.php tests/phpunit/tests/formatting/SanitizeFileName.php
index 8927fec..b3b3003 100644
|
|
class Tests_Formatting_SanitizeFileName extends WP_UnitTestCase { |
56 | 56 | function test_replaces_percent_sign() { |
57 | 57 | $this->assertEquals( 'a22b.jpg', sanitize_file_name( 'a%22b.jpg' ) ); |
58 | 58 | } |
| 59 | |
| 60 | function test_replaces_unnammed_file_extentions() { |
| 61 | // Test filenames with both supported and unsupported extensions. |
| 62 | $this->assertEquals( 'unnamed-file.exe', sanitize_file_name( '_.exe' ) ); |
| 63 | $this->assertEquals( 'unnamed-file.jpg', sanitize_file_name( '_.jpg' ) ); |
| 64 | } |
| 65 | |
| 66 | function test_replaces_unnammed_file_extentionless() { |
| 67 | // Test a filenames that becomes extentionless. |
| 68 | $this->assertEquals( 'no-extention', sanitize_file_name( '_.no-extention' ) ); |
| 69 | } |
59 | 70 | } |