From ce87b260bcd0b4223b524f03140bc37bfb8d4ae3 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 26 Sep 2020 01:09:52 +0000 Subject: [PATCH] Upload: Add a check in `wp_check_filetype_and_ext()` to account for CSV files having the `application/csv` MIME type. Previously, the PHP Fileinfo extension used to detect CSV files as `text/plain`. In PHP 8, this has changed, and CSV files are detected as `application/csv`. Follow-up to [44438]. See #50913. git-svn-id: https://develop.svn.wordpress.org/trunk@49049 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 87f3fec895..8df5788119 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -2933,6 +2933,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { array( 'text/plain', 'text/csv', + 'application/csv', 'text/richtext', 'text/tsv', 'text/vtt', @@ -2943,6 +2944,21 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { $type = false; $ext = false; } + } elseif ( 'application/csv' === $real_mime ) { + // Special casing for CSV files. + if ( ! in_array( + $type, + array( + 'text/csv', + 'text/plain', + 'application/csv', + ), + true + ) + ) { + $type = false; + $ext = false; + } } elseif ( 'text/rtf' === $real_mime ) { // Special casing for RTF files. if ( ! in_array(