Make WordPress Core

Ticket #56969: 56969.2.diff

File 56969.2.diff, 1.7 KB (added by adamsilverstein, 16 months ago)
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index bfd71cdcb3..804a34f6ac 100644
    function wp_img_tag_add_loading_attr( $image, $context ) { 
    19621962 * @return string Converted `img` tag with `decoding` attribute added.
    19631963 */
    19641964function wp_img_tag_add_decoding_attr( $image, $context ) {
     1965        // Only apply the decoding attribute to images that have a src attribute that
     1966        // starts with a double quote, ensuring escaped JSON is also excluded.
     1967        if ( false === strpos( $image, ' src="' ) ) {
     1968                return $image;
     1969        }
     1970
    19651971        /**
    19661972         * Filters the `decoding` attribute value to add to an image. Default `async`.
    19671973         *
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index 0d5ac75863..4d5ba64e29 100644
    EOF; 
    31623162                $this->assertStringNotContainsString( ' loading=', $img );
    31633163        }
    31643164
     3165        /**
     3166         * Test that decoding="async" is not applied to img tags with single quotes.
     3167         *
     3168         * @ticket 56969
     3169         */
     3170        public function test_wp_img_tag_add_decoding_attr_with_single_quotes() {
     3171                $img = "<img src='example.png' alt='' width='300' height='225' />";
     3172                $img = wp_img_tag_add_decoding_attr( $img, 'test' );
     3173                $this->assertStringNotContainsString( ' decoding="async"', $img );
     3174        }
     3175
     3176        /**
     3177         * Test that decoding="async" is not applied to img tags inside JSON.
     3178         *
     3179         * @ticket 56969
     3180         */
     3181        public function test_decoding_async_not_applied_to_json() {
     3182                $content = '{"image": "<img src=\"example.png\" alt=\"\" width=\"300\" height=\"225\" />"}';
     3183                $content = wp_filter_content_tags( $content );
     3184                $this->assertStringNotContainsString( ' decoding="async"', $content );
     3185        }
     3186
    31653187        /**
    31663188         * @ticket 50756
    31673189         */