X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/784f914b1e4b1c62d6657e86397c2e83bcee4295..refs/tags/wordpress-4.5.3:/wp-includes/formatting.php diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 14f3852b..9f4597d1 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -1364,7 +1364,8 @@ function remove_accents( $string ) { * operating systems and special characters requiring special escaping * to manipulate at the command line. Replaces spaces and consecutive * dashes with a single dash. Trims period, dash and underscore from beginning - * and end of filename. + * and end of filename. It is not guaranteed that this function will return a + * filename that is allowed to be uploaded. * * @since 2.1.0 * @@ -1389,6 +1390,14 @@ function sanitize_file_name( $filename ) { $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename ); $filename = trim( $filename, '.-_' ); + if ( false === strpos( $filename, '.' ) ) { + $mime_types = wp_get_mime_types(); + $filetype = wp_check_filetype( 'test.' . $filename, $mime_types ); + if ( $filetype['ext'] === $filename ) { + $filename = 'unnamed-file.' . $filetype['ext']; + } + } + // Split the filename into a base and extension[s] $parts = explode('.', $filename); @@ -4582,7 +4591,7 @@ function print_emoji_detection_script() { ?>