diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 93b4df2df4505..1382f2c10c07c 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -3247,6 +3247,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { 'text/richtext', 'text/tsv', 'text/vtt', + 'application/json', ), true ) diff --git a/tests/phpunit/data/uploads/test.json b/tests/phpunit/data/uploads/test.json new file mode 100644 index 0000000000000..7deb8b173227b --- /dev/null +++ b/tests/phpunit/data/uploads/test.json @@ -0,0 +1 @@ +"just a string" diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index b6080da780ba8..ba26d7f99e268 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -1839,6 +1839,32 @@ public function data_wp_check_filetype_and_ext() { return $data; } + /** + * @ticket 54193 + * @group ms-excluded + * @requires extension fileinfo + */ + public function test_wp_check_filetype_and_ext_with_filtered_json() { + $file = DIR_TESTDATA . '/uploads/test.json'; + $filename = 'test.json'; + + $expected = array( + 'ext' => 'json', + 'type' => 'application/json', + 'proper_filename' => false, + ); + + add_filter( + 'upload_mimes', + static function ( $mimes ) { + $mimes['json'] = 'application/json'; + return $mimes; + } + ); + + $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); + } + /** * @ticket 39550 * @group ms-excluded