From e6cfabe956c517ac2f6214f43ef1cb2b923824ac Mon Sep 17 00:00:00 2001 From: joedolson Date: Thu, 30 May 2024 13:03:12 +0000 Subject: [PATCH] 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 --- wp-includes/post.php | 5 +++++ wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 1a91a183ad..b0967dbad8 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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(); diff --git a/wp-includes/version.php b/wp-includes/version.php index 44e2622217..4a07b0f97c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.