Make WordPress Core


Ignore:
Timestamp:
09/03/2023 12:49:51 PM (19 months ago)
Author:
SergeyBiryukov
Message:

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: PHP Bug #77784: mime_content_type() result gets doubled for .xlsx.

Follow-up to [56497].

See #57898.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r56497 r56510  
    31513151        finfo_close( $finfo );
    31523152
    3153         // finfo_file() returns redudant mime type for Google docs, see #57898.
    3154         if ( 'application/vnd.openxmlformats-officedocument.wordprocessingml.documentapplication/vnd.openxmlformats-officedocument.wordprocessingml.document' === $real_mime ) {
    3155             $real_mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
     3153        $google_docs_types = array(
     3154            'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
     3155            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
     3156        );
     3157
     3158        foreach ( $google_docs_types as $google_docs_type ) {
     3159            /*
     3160             * finfo_file() can return duplicate mime type for Google docs,
     3161             * this conditional reduces it to a single instance.
     3162             *
     3163             * @see https://bugs.php.net/bug.php?id=77784
     3164             * @see https://core.trac.wordpress.org/ticket/57898
     3165             */
     3166            if ( 2 === substr_count( $real_mime, $google_docs_type ) ) {
     3167                $real_mime = $google_docs_type;
     3168            }
    31563169        }
    31573170
Note: See TracChangeset for help on using the changeset viewer.