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
This commit is contained in:
parent
b59b9f466a
commit
a411918199
@ -2049,7 +2049,7 @@ function wp_check_filetype( $filename, $mimes = null ) {
|
|||||||
$ext = false;
|
$ext = false;
|
||||||
|
|
||||||
foreach ( $mimes as $ext_preg => $mime_match ) {
|
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 ) ) {
|
if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {
|
||||||
$type = $mime_match;
|
$type = $mime_match;
|
||||||
$ext = $ext_matches[1];
|
$ext = $ext_matches[1];
|
||||||
|
@ -467,4 +467,13 @@ VIDEO;
|
|||||||
return $dir;
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user