WordPress.org

Make WordPress Core

Ticket #35480: 35480.3.patch

File 35480.3.patch, 1.8 KB (added by joemcgill, 4 years ago)
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 7b99f95..9bd54be 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'] ) || strlen( $image_meta['file'] ) < 4 ) {
     988        if ( empty( $image_meta['sizes'] ) || ( ! isset( $image_meta['file'] ) ) || strlen( $image_meta['file'] ) < 4 ) {
    989989                return false;
    990990        }
    991991
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index 5399f85..5b68f32 100644
    EOF; 
    11841184                $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta2 ) );
    11851185
    11861186                // File name is incorrect
     1187                $image_meta3 = $image_meta;
     1188                $image_meta3['file'] = '/';
     1189                $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta3 ) );
     1190
     1191                // File name is incorrect
    11871192                $image_meta4 = $image_meta;
    1188                 $image_meta4['file'] = '/';
     1193                unset( $image_meta4['file'] );
    11891194                $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta4 ) );
    11901195
    11911196                // Intermediate size is string instead of array.
    1192                 $image_meta3 = $image_meta;
    1193                 $image_meta3['sizes']['medium_large'] = '';
     1197                $image_meta5 = $image_meta;
     1198                $image_meta5['sizes']['medium_large'] = '';
    11941199                unset( $srcset[768] );
    11951200                $expected_srcset = implode( ', ', $srcset );
    1196                 $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta3 ) );
     1201                $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta5 ) );
    11971202        }
    11981203
    11991204        /**