Changeset 37756
- Timestamp:
- 06/21/2016 01:43:59 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/formatting.php
r37747 r37756 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 … … 1750 1751 $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename ); 1751 1752 $filename = trim( $filename, '.-_' ); 1753 1754 if ( false === strpos( $filename, '.' ) ) { 1755 $mime_types = wp_get_mime_types(); 1756 $filetype = wp_check_filetype( 'test.' . $filename, $mime_types ); 1757 if ( $filetype['ext'] === $filename ) { 1758 $filename = 'unnamed-file.' . $filetype['ext']; 1759 } 1760 } 1752 1761 1753 1762 // Split the filename into a base and extension[s] -
trunk/tests/phpunit/tests/formatting/SanitizeFileName.php
r35122 r37756 57 57 $this->assertEquals( 'a22b.jpg', sanitize_file_name( 'a%22b.jpg' ) ); 58 58 } 59 60 function test_replaces_unnammed_file_extensions() { 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_extensionless() { 67 // Test a filenames that becomes extensionless. 68 $this->assertEquals( 'no-extension', sanitize_file_name( '_.no-extension' ) ); 69 } 59 70 }
Note: See TracChangeset
for help on using the changeset viewer.