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.

Built from https://develop.svn.wordpress.org/trunk@52829


git-svn-id: http://core.svn.wordpress.org/trunk@52418 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
audrasjb 2022-03-07 22:52:05 +00:00
parent 2399966d8c
commit 28f7345fce
2 changed files with 12 additions and 2 deletions

View File

@ -2981,8 +2981,9 @@ function wp_get_default_extension_for_mime_type( $mime_type ) {
* You can optionally define the mime array, if needed. * You can optionally define the mime array, if needed.
* *
* @since 2.0.4 * @since 2.0.4
* @since 6.0.0 URLs are now supported.
* *
* @param string $filename File name or path. * @param string $filename File name, path, or URL.
* @param string[] $mimes Optional. Array of allowed mime types keyed by their file extension regex. * @param string[] $mimes Optional. Array of allowed mime types keyed by their file extension regex.
* @return array { * @return array {
* Values for the extension and mime type. * Values for the extension and mime type.
@ -2998,6 +2999,15 @@ function wp_check_filetype( $filename, $mimes = null ) {
$type = false; $type = false;
$ext = false; $ext = false;
// Strip query args and fragment from filename to reveal extension.
$query_pos = strpos( $filename, '?' );
if ( false !== $query_pos ) {
$filename = substr_replace( $filename, '', $query_pos );
}
$filename = strip_fragment_from_url( $filename );
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 ) ) {

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.0-alpha-52828'; $wp_version = '6.0-alpha-52829';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.