From a41191819971ef535a0f21f3d29406f01575e00b Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sun, 30 Nov 2014 06:32:16 +0000 Subject: [PATCH] Adjust the RegEx in `wp_check_filetype()` to be aware that query strings are thing that exist sometimes in URLs. Adds unit tests. Props voldemortensen. Fixes #30377. git-svn-id: https://develop.svn.wordpress.org/trunk@30640 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 2 +- tests/phpunit/tests/media.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 173fb80190..a751ac04a5 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -2049,7 +2049,7 @@ function wp_check_filetype( $filename, $mimes = null ) { $ext = false; foreach ( $mimes as $ext_preg => $mime_match ) { - $ext_preg = '!\.(' . $ext_preg . ')$!i'; + $ext_preg = '!\.(' . $ext_preg . ')(\?.*)?$!i'; if ( preg_match( $ext_preg, $filename, $ext_matches ) ) { $type = $mime_match; $ext = $ext_matches[1]; diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index c22bf623fc..4523e4ee3b 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -467,4 +467,13 @@ VIDEO; return $dir; } + function test_wp_check_filetype() { + $url = 'http://example.com/testFile.mp4?autoplay=true&otherstuff=false'; + $filetype = wp_check_filetype( $url ); + $expected = array( + 'ext' => 'mp4', + 'type' => 'video/mp4' + ); + $this->assertEquals( $expected, $filetype ); + } }