diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index eac938b2c4d1a..02c462f66d1fe 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -3342,6 +3342,12 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { $type = false; $ext = false; } + } elseif ( 'text/html' === $real_mime ) { + // CSV files can contain HTML in their fields. + if ( 'text/csv' !== $type ) { + $type = false; + $ext = false; + } } elseif ( 'text/rtf' === $real_mime ) { // Special casing for RTF files. if ( ! in_array( diff --git a/tests/phpunit/data/uploads/test-html-in-csv.csv b/tests/phpunit/data/uploads/test-html-in-csv.csv new file mode 100644 index 0000000000000..e798747e3ee3c --- /dev/null +++ b/tests/phpunit/data/uploads/test-html-in-csv.csv @@ -0,0 +1 @@ +,

Product description with HTML markup

, diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 64d84458c334f..47696af2fe6d1 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -1714,6 +1714,16 @@ public static function data_wp_check_filetype_and_ext() { 'proper_filename' => false, ), ), + // HTML content is not allowed when using a non-CSV extension. + array( + DIR_TESTDATA . '/uploads/test-html-in-csv.csv', + 'test-html-in-csv.jpg', + array( + 'ext' => false, + 'type' => false, + 'proper_filename' => false, + ), + ), ); // Test a few additional file types on single sites. @@ -1780,6 +1790,15 @@ public static function data_wp_check_filetype_and_ext() { 'proper_filename' => false, ), ), + array( + DIR_TESTDATA . '/uploads/test-html-in-csv.csv', + 'test-html-in-csv.csv', + array( + 'ext' => 'csv', + 'type' => 'text/csv', + 'proper_filename' => false, + ), + ), // RTF files. array( DIR_TESTDATA . '/uploads/test.rtf',