Make WordPress Core

Ticket #35480: 35480.1.patch

File 35480.1.patch, 3.5 KB (added by jaspermdegroot, 9 years ago)
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 6b0187a..d826e6c 100644
    function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac 
    985985         */
    986986        $image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id );
    987987
    988         if ( empty( $image_meta['sizes'] ) ) {
     988        if ( empty( $image_meta['sizes'] ) || 1 > strpos( $image_meta['file'], '.' ) ) {
    989989                return false;
    990990        }
    991991
    function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac 
    10601060         */
    10611061        foreach ( $image_sizes as $image ) {
    10621062
     1063                // Check if image meta isn't corrupted.
     1064                if ( ! is_array( $image ) ) {
     1065                        continue;
     1066                }
     1067
    10631068                // If the file name is part of the `src`, we've confirmed a match.
    10641069                if ( ! $src_matched && false !== strpos( $image_src, $dirname . $image['file'] ) ) {
    10651070                        $src_matched = true;
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index d5ae231..5399f85 100644
    EOF; 
    11291129        }
    11301130
    11311131        /**
     1132         * @ticket 35480
     1133         */
     1134        function test_wp_calculate_image_srcset_corrupted_image_meta() {
     1135                $size_array = array( 300, 150 );
     1136                $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png';
     1137                $image_meta = array(
     1138                        'width' => 1600,
     1139                        'height' => 800,
     1140                        'file' => '2015/12/test.png',
     1141                        'sizes' => array(
     1142                                'thumbnail' => array(
     1143                                        'file' => 'test-150x150.png',
     1144                                        'width' => 150,
     1145                                        'height' => 150,
     1146                                        'mime-type' => 'image/png',
     1147                                ),
     1148                                'medium' => array(
     1149                                        'file' => 'test-300x150.png',
     1150                                        'width' => 300,
     1151                                        'height' => 150,
     1152                                        'mime-type' => 'image/png',
     1153                                ),
     1154                                'medium_large' => array(
     1155                                        'file' => 'test-768x384.png',
     1156                                        'width' => 768,
     1157                                        'height' => 384,
     1158                                        'mime-type' => 'image/png',
     1159                                ),
     1160                                'large' => array(
     1161                                        'file' => 'test-1024x512.png',
     1162                                        'width' => 1024,
     1163                                        'height' => 512,
     1164                                        'mime-type' => 'image/png',
     1165                                ),
     1166                        ),
     1167                );
     1168
     1169                $srcset = array(
     1170                        300  => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png 300w',
     1171                        768  => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x384.png 768w',
     1172                        1024 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-1024x512.png 1024w',
     1173                        1600 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png 1600w',
     1174                );
     1175
     1176                // No sizes array
     1177                $image_meta1 = $image_meta;
     1178                unset( $image_meta1['sizes'] );
     1179                $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta1 ) );
     1180
     1181                // Sizes is string instead of array; only full size available means no srcset.
     1182                $image_meta2 = $image_meta;
     1183                $image_meta2['sizes'] = '';
     1184                $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta2 ) );
     1185
     1186                // File name is incorrect
     1187                $image_meta4 = $image_meta;
     1188                $image_meta4['file'] = '/';
     1189                $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta4 ) );
     1190
     1191                // Intermediate size is string instead of array.
     1192                $image_meta3 = $image_meta;
     1193                $image_meta3['sizes']['medium_large'] = '';
     1194                unset( $srcset[768] );
     1195                $expected_srcset = implode( ', ', $srcset );
     1196                $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta3 ) );
     1197        }
     1198
     1199        /**
    11321200         * @ticket 33641
    11331201         */
    11341202        function test_wp_get_attachment_image_srcset() {