Changeset 37819
- Timestamp:
- 06/21/2016 02:57:23 PM (7 years ago)
- Location:
- branches/4.0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.0/src/wp-includes/formatting.php
r33522 r37819 1151 1151 * to manipulate at the command line. Replaces spaces and consecutive 1152 1152 * dashes with a single dash. Trims period, dash and underscore from beginning 1153 * and end of filename. 1153 * and end of filename. It is not guaranteed that this function will return a 1154 * filename that is allowed to be uploaded. 1154 1155 * 1155 1156 * @since 2.1.0 … … 1175 1176 $filename = preg_replace('/[\s-]+/', '-', $filename); 1176 1177 $filename = trim($filename, '.-_'); 1178 1179 if ( false === strpos( $filename, '.' ) ) { 1180 $mime_types = wp_get_mime_types(); 1181 $filetype = wp_check_filetype( 'test.' . $filename, $mime_types ); 1182 if ( $filetype['ext'] === $filename ) { 1183 $filename = 'unnamed-file.' . $filetype['ext']; 1184 } 1185 } 1177 1186 1178 1187 // Split the filename into a base and extension[s] -
branches/4.0/tests/phpunit/tests/formatting/SanitizeFileName.php
r29290 r37819 50 50 $this->assertEquals("a-t", sanitize_file_name("a \n\n\nt")); 51 51 } 52 53 function test_replaces_unnammed_file_extensions() { 54 // Test filenames with both supported and unsupported extensions. 55 $this->assertEquals( 'unnamed-file.exe', sanitize_file_name( '_.exe' ) ); 56 $this->assertEquals( 'unnamed-file.jpg', sanitize_file_name( '_.jpg' ) ); 57 } 58 59 function test_replaces_unnammed_file_extensionless() { 60 // Test a filenames that becomes extensionless. 61 $this->assertEquals( 'no-extension', sanitize_file_name( '_.no-extension' ) ); 62 } 52 63 }
Note: See TracChangeset
for help on using the changeset viewer.