Make WordPress Core

Changeset 58248


Ignore:
Timestamp:
05/30/2024 01:01:44 PM (12 months ago)
Author:
joedolson
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r58225 r58248  
    68716871    }
    68726872
     6873    // Check if preferred file format variable is present and is a validly formatted file extension.
     6874    if ( ! empty( $preferred_ext ) && is_string( $preferred_ext ) && ! str_starts_with( $preferred_ext, '.' ) ) {
     6875        $preferred_ext = '.' . strtolower( $preferred_ext );
     6876    }
     6877
    68736878    $post_id = 0;
    68746879    if ( empty( $icon ) ) {
  • trunk/tests/phpunit/tests/post/attachments.php

    r54226 r58248  
    520520        $this->assertStringContainsString( 'images/media/video.png', $icon );
    521521    }
     522
     523    /**
     524     * @ticket 60610
     525     */
     526    public function test_wp_mime_type_icon_video_with_preferred_ext() {
     527        $icon1 = wp_mime_type_icon( 'video/mp4', '.png' ); // Added `$preferred_ext` parameter.
     528        $icon2 = wp_mime_type_icon( 'video/mp4', 'png' ); // Added `$preferred_ext` parameter without period.
     529
     530        $this->assertStringContainsString( 'images/media/video.png', $icon1, 'Mime type icon should be correctly returned with ".png" argument.' );
     531        $this->assertStringContainsString( 'images/media/video.png', $icon2, 'Mime type icon should be correctly returned with "png" argument.' );
     532    }
    522533}
Note: See TracChangeset for help on using the changeset viewer.