diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 8c209ec6bf..b00a47c1d8 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -2574,23 +2574,29 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { } } elseif ( 'text/plain' === $real_mime ) { // A few common file types are occasionally detected as text/plain; allow those. - if ( ! in_array( $type, array( + if ( ! in_array( + $type, + array( 'text/plain', 'text/csv', 'text/richtext', 'text/tsv', 'text/vtt', - ) ) + ) + ) ) { $type = $ext = false; } - } elseif( 'text/rtf' === $real_mime ) { + } elseif ( 'text/rtf' === $real_mime ) { // Special casing for RTF files. - if ( ! in_array( $type, array( + if ( ! in_array( + $type, + array( 'text/rtf', 'text/plain', 'application/rtf', - ) ) + ) + ) ) { $type = $ext = false; } diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 6a7c447c28..c7c0b2d1ab 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -1341,8 +1341,8 @@ class Tests_Functions extends WP_UnitTestCase { DIR_TESTDATA . '/export/crazy-cdata.xml', 'crazy-cdata.jpg', array( - 'ext' => false, - 'type' => false, + 'ext' => false, + 'type' => false, 'proper_filename' => false, ), ), @@ -1351,8 +1351,8 @@ class Tests_Functions extends WP_UnitTestCase { DIR_TESTDATA . '/export/crazy-cdata.xml', 'crazy-cdata.doc', array( - 'ext' => false, - 'type' => false, + 'ext' => false, + 'type' => false, 'proper_filename' => false, ), ), @@ -1361,8 +1361,8 @@ class Tests_Functions extends WP_UnitTestCase { DIR_TESTDATA . '/uploads/test.vtt', 'test.vtt', array( - 'ext' => 'vtt', - 'type' => 'text/vtt', + 'ext' => 'vtt', + 'type' => 'text/vtt', 'proper_filename' => false, ), ), @@ -1370,8 +1370,8 @@ class Tests_Functions extends WP_UnitTestCase { DIR_TESTDATA . '/uploads/test.csv', 'test.csv', array( - 'ext' => 'csv', - 'type' => 'text/csv', + 'ext' => 'csv', + 'type' => 'text/csv', 'proper_filename' => false, ), ), @@ -1380,8 +1380,8 @@ class Tests_Functions extends WP_UnitTestCase { DIR_TESTDATA . '/uploads/test.rtf', 'test.rtf', array( - 'ext' => 'rtf', - 'type' => 'application/rtf', + 'ext' => 'rtf', + 'type' => 'application/rtf', 'proper_filename' => false, ), ),