Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/data/uploads/test-html-in-csv.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html>,<body><p>Product description with HTML markup</p></body></html>,
19 changes: 19 additions & 0 deletions tests/phpunit/tests/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand Down
Loading