From dc9517a3e0fb920dee37d6c4d44005b012782590 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 3 Sep 2023 12:51:20 +0000 Subject: [PATCH] Upload: Correct duplicate MIME type for `.xlsx` files generated by Google Docs. This expands the code block previously added for `.docx` files to include `.xlsx` files as well, which are known to have the same issue with `finfo_file()`. Includes a unit test case for `wp_check_filetype_and_ext()`. Reference: [https://bugs.php.net/bug.php?id=77784 PHP Bug #77784: mime_content_type() result gets doubled for .xlsx]. Follow-up to [56497]. See #57898. Built from https://develop.svn.wordpress.org/trunk@56510 git-svn-id: http://core.svn.wordpress.org/trunk@56022 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 19 ++++++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index dfe8af4335..e0c859cc8f 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3150,9 +3150,22 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { $real_mime = finfo_file( $finfo, $file ); finfo_close( $finfo ); - // finfo_file() returns redudant mime type for Google docs, see #57898. - if ( 'application/vnd.openxmlformats-officedocument.wordprocessingml.documentapplication/vnd.openxmlformats-officedocument.wordprocessingml.document' === $real_mime ) { - $real_mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + $google_docs_types = array( + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + ); + + foreach ( $google_docs_types as $google_docs_type ) { + /* + * finfo_file() can return duplicate mime type for Google docs, + * this conditional reduces it to a single instance. + * + * @see https://bugs.php.net/bug.php?id=77784 + * @see https://core.trac.wordpress.org/ticket/57898 + */ + if ( 2 === substr_count( $real_mime, $google_docs_type ) ) { + $real_mime = $google_docs_type; + } } // fileinfo often misidentifies obscure files as one of these types. diff --git a/wp-includes/version.php b/wp-includes/version.php index d816dc53c5..12e9bf333d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56509'; +$wp_version = '6.4-alpha-56510'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.