Make WordPress Core

Changeset 40397 for trunk


Ignore:
Timestamp:
04/09/2017 10:43:04 PM (9 years ago)
Author:
joemcgill
Message:

Media: Improve handling of non-image files in wp_get_image_mime.

This prevents non-image fileypes from returning a mime type of
"application/octet-stream" when exif_imagetype() returns false.

Props blobfolio.
Fixes #40017.

Location:
trunk
Files:
2 edited

Legend:

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

    r40124 r40397  
    23682368        try {
    23692369                if ( is_callable( 'exif_imagetype' ) ) {
    2370                         $mime = image_type_to_mime_type( exif_imagetype( $file ) );
     2370                        $imagetype = exif_imagetype( $file );
     2371                        $mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
    23712372                } elseif ( function_exists( 'getimagesize' ) ) {
    23722373                        $imagesize = getimagesize( $file );
  • trunk/tests/phpunit/tests/functions.php

    r40125 r40397  
    917917
    918918        /**
     919         * @ticket 40017
     920         * @dataProvider _wp_get_image_mime
     921         */
     922        public function test_wp_get_image_mime( $file, $expected ) {
     923                if ( ! is_callable( 'exif_imagetype' ) && ! function_exists( 'getimagesize' ) ) {
     924                        $this->markTestSkipped( 'The exif PHP extension is not loaded.' );
     925                }
     926
     927                $this->assertEquals( $expected, wp_get_image_mime( $file ) );
     928        }
     929
     930        /**
    919931         * @ticket 39550
    920932         * @dataProvider _wp_check_filetype_and_ext_data
     
    9921004                $mimes['woff'] = 'application/font-woff';
    9931005                return $mimes;
     1006        }
     1007
     1008        /**
     1009         * Data profider for test_wp_get_image_mime();
     1010         */
     1011        public function _wp_get_image_mime() {
     1012                $data = array(
     1013                        // Standard JPEG.
     1014                        array(
     1015                                DIR_TESTDATA . '/images/test-image.jpg',
     1016                                'image/jpeg',
     1017                        ),
     1018                        // Standard GIF.
     1019                        array(
     1020                                DIR_TESTDATA . '/images/test-image.gif',
     1021                                'image/gif',
     1022                        ),
     1023                        // Standard PNG.
     1024                        array(
     1025                                DIR_TESTDATA . '/images/test-image.png',
     1026                                'image/png',
     1027                        ),
     1028                        // Image with wrong extension.
     1029                        array(
     1030                                DIR_TESTDATA . '/images/test-image-mime-jpg.png',
     1031                                'image/jpeg',
     1032                        ),
     1033                        // Not an image.
     1034                        array(
     1035                                DIR_TESTDATA . '/uploads/dashicons.woff',
     1036                                false,
     1037                        ),
     1038                );
     1039
     1040                return $data;
    9941041        }
    9951042
Note: See TracChangeset for help on using the changeset viewer.