Make WordPress Core

Changeset 56510


Ignore:
Timestamp:
09/03/2023 12:49:51 PM (7 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.

Location:
trunk
Files:
1 added
2 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
  • trunk/tests/phpunit/tests/functions.php

    r55711 r56510  
    16441644                        ),
    16451645                    ),
     1646                    // Google Docs file for which finfo_file() returns a duplicate mime type.
     1647                    array(
     1648                        DIR_TESTDATA . '/uploads/double-mime-type.docx',
     1649                        'double-mime-type.docx',
     1650                        array(
     1651                            'ext'             => 'docx',
     1652                            'type'            => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
     1653                            'proper_filename' => false,
     1654                        ),
     1655                    ),
    16461656                    // Non-image file with wrong sub-type.
    16471657                    array(
Note: See TracChangeset for help on using the changeset viewer.