Media: Protect mime type icon function from simple errors.

Handle `$preferred_ext` arguments that are passed with minor errors in formatting, such as incorrect casing or missing `.`. Add unit tests to verify that an omitted period on an otherwise correct extension is accepted. Follow up to [57687].

Props sabernhardt, joedolson, khokansardar.
Fixes #60610.
Built from https://develop.svn.wordpress.org/trunk@58248


git-svn-id: http://core.svn.wordpress.org/trunk@57711 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2024-05-30 13:03:12 +00:00
parent b2d74b21b9
commit e6cfabe956
2 changed files with 6 additions and 1 deletions

View File

@ -6870,6 +6870,11 @@ function wp_mime_type_icon( $mime = 0, $preferred_ext = '.png' ) {
$icon = wp_cache_get( "mime_type_icon_$mime" );
}
// Check if preferred file format variable is present and is a validly formatted file extension.
if ( ! empty( $preferred_ext ) && is_string( $preferred_ext ) && ! str_starts_with( $preferred_ext, '.' ) ) {
$preferred_ext = '.' . strtolower( $preferred_ext );
}
$post_id = 0;
if ( empty( $icon ) ) {
$post_mimes = array();

View File

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