From 2bdc11781d25436b9d037b0d64b611f1a346c1f8 Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Tue, 21 Jun 2016 13:44:31 +0000 Subject: [PATCH] Media: Improve handling of extensionless filenames. This ensures files retain a filename after sanitization. Fixes 37111. Built from https://develop.svn.wordpress.org/trunk@37756 git-svn-id: http://core.svn.wordpress.org/trunk@37721 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 11 ++++++++++- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 905e6b2388..719132783b 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -1725,7 +1725,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 * @@ -1750,6 +1751,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); diff --git a/wp-includes/version.php b/wp-includes/version.php index 300b82fa66..76bd3c2130 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-alpha-37755'; +$wp_version = '4.6-alpha-37756'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.