From ac1ff028151e9ff0490fa43b28b8698142347d09 Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Mon, 7 Jan 2019 20:48:51 +0000 Subject: [PATCH] Upload: Fix upload failures of common text file types. This adds some special case handling in 'wp_check_filetype_and_ext()' that prevents some common file types from being blocked based on mismatched MIME checks, which were made more strict in WordPress 5.0.1. Props Kloon, birgire, tellyworth, joemcgill. See #45615. Built from https://develop.svn.wordpress.org/trunk@44438 git-svn-id: http://core.svn.wordpress.org/trunk@44269 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 23 ++++++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 439a2a30ce..8c209ec6bf 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -2569,10 +2569,31 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { * This means that common mismatches are forgiven: application/vnd.apple.numbers is often misidentified as application/zip, * and some media files are commonly named with the wrong extension (.mov instead of .mp4) */ - if ( substr( $real_mime, 0, strcspn( $real_mime, '/' ) ) !== substr( $type, 0, strcspn( $type, '/' ) ) ) { $type = $ext = false; } + } elseif ( 'text/plain' === $real_mime ) { + // A few common file types are occasionally detected as text/plain; allow those. + if ( ! in_array( $type, array( + 'text/plain', + 'text/csv', + 'text/richtext', + 'text/tsv', + 'text/vtt', + ) ) + ) { + $type = $ext = false; + } + } elseif( 'text/rtf' === $real_mime ) { + // Special casing for RTF files. + if ( ! in_array( $type, array( + 'text/rtf', + 'text/plain', + 'application/rtf', + ) ) + ) { + $type = $ext = false; + } } else { if ( $type !== $real_mime ) { /* diff --git a/wp-includes/version.php b/wp-includes/version.php index 282f832361..f9a7c51a77 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-alpha-44437'; +$wp_version = '5.1-alpha-44438'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.