mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Media: Allow wp_check_filetype() to support query strings in URLs.
This changeset adjusts the regex in `wp_check_filetype()` to support query strings in URLs. Follow-up to [30640], [32172]. Props voldemortensen, johnbillion, layotte, dd32, atomicjack, supercleanse, spencercameron, ianmjones, audrasjb. Fixes #30377. git-svn-id: https://develop.svn.wordpress.org/trunk@52829 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
58
tests/phpunit/tests/functions/wpCheckFiletype.php
Normal file
58
tests/phpunit/tests/functions/wpCheckFiletype.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tests for wp_check_filetype()
|
||||
*
|
||||
* @group functions.php
|
||||
* @covers ::wp_check_filetype
|
||||
*/
|
||||
class Tests_Functions_wpCheckFiletype extends WP_UnitTestCase {
|
||||
|
||||
public function data_url_filetypes() {
|
||||
return array(
|
||||
// Invalid or empty data:
|
||||
array( null, false ),
|
||||
array( '', false ),
|
||||
array( ' ', false ),
|
||||
|
||||
// Paths:
|
||||
array( 'file.jpg', 'jpg' ),
|
||||
array( 'C:\path\to\file.mp3', 'mp3' ),
|
||||
array( 'C:\path\to\file.mp3?file.jpg', 'mp3' ),
|
||||
array( 'C:\path\to\file.exe?file.jpg', false ),
|
||||
array( '/file.jpg', 'jpg' ),
|
||||
array( '/path/to/file.jpg', 'jpg' ),
|
||||
array( '/path/to/file.jpg', 'jpg' ),
|
||||
array( '/file.exe?file.jpg', false ),
|
||||
|
||||
// Absolute URLs:
|
||||
array( 'http://example.com', false ),
|
||||
array( 'http://example.com/', false ),
|
||||
array( 'http://example.com/wibble', false ),
|
||||
array( 'http://example.com/wibble/', false ),
|
||||
array( 'http://example.com/wibble.wobble', false ),
|
||||
array( 'http://example.com/wibble.mp3', 'mp3' ),
|
||||
array( 'http://example.com/wibble.mp3#wobble', 'mp3' ),
|
||||
array( 'http://example.com/wibble.mp3?wobble=true', 'mp3' ),
|
||||
array( 'http://example.com/wibble.mp3?wobble=true#wobble', 'mp3' ),
|
||||
array( 'http://example.mp3/', false ),
|
||||
array( 'http://example.com/file.mp3#file.jpg', 'mp3' ),
|
||||
array( 'http://example.com/file.mp3?file.jpg', 'mp3' ),
|
||||
array( 'http://example.com/file.exe#file.jpg', false ),
|
||||
array( 'http://example.com/file.exe?file.jpg', false ),
|
||||
array( 'http://example.com/file.mp3?foo=bar#?file=file.jpg', 'mp3' ),
|
||||
array( 'http://example.com?file.jpg', false ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_url_filetypes
|
||||
*
|
||||
* @param string $url
|
||||
* @param string|false $expected
|
||||
*/
|
||||
public function test_url_ext( $url, $expected ) {
|
||||
$filetype = wp_check_filetype( $url );
|
||||
$this->assertSame( $expected, $filetype['ext'] );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user