diff --git src/wp-includes/media.php src/wp-includes/media.php
index bfd71cdcb3..96fdb5171b 100644
|
|
function wp_img_tag_add_loading_attr( $image, $context ) { |
1962 | 1962 | * @return string Converted `img` tag with `decoding` attribute added. |
1963 | 1963 | */ |
1964 | 1964 | function wp_img_tag_add_decoding_attr( $image, $context ) { |
| 1965 | |
| 1966 | // Only apply the decoding attribute to images that have a src attribute that |
| 1967 | // starts with a double quote, ensuring escaped JSON is also excluded. |
| 1968 | if ( false === strpos( $image, ' src="' ) ) { |
| 1969 | return $image; |
| 1970 | } |
| 1971 | |
1965 | 1972 | /** |
1966 | 1973 | * Filters the `decoding` attribute value to add to an image. Default `async`. |
1967 | 1974 | * |
diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
index 0d5ac75863..a213308875 100644
|
|
EOF; |
3162 | 3162 | $this->assertStringNotContainsString( ' loading=', $img ); |
3163 | 3163 | } |
3164 | 3164 | |
| 3165 | |
| 3166 | |
| 3167 | /** |
| 3168 | * Test that decoding="async" is not applied to img tags with single quotes. |
| 3169 | * |
| 3170 | * @ticket 56969 |
| 3171 | */ |
| 3172 | public function test_wp_img_tag_add_decoding_attr_with_single_quotes() { |
| 3173 | $img = "<img src='example.png' alt=' width='300' height='225' />"; |
| 3174 | $img = wp_img_tag_add_decoding_attr( $img, 'test' ); |
| 3175 | |
| 3176 | $this->assertStringNotContainsString( ' decoding="async"', $img ); |
| 3177 | } |
| 3178 | |
| 3179 | /** |
| 3180 | * Test that decoding="async" os not applied to img tags inside JSON. |
| 3181 | * |
| 3182 | * @ticket 56969 |
| 3183 | */ |
| 3184 | public function test_decoding_async_not_applied_to_json() { |
| 3185 | $content = '{"image": "<img src=\"example.png\" alt=\" width=\"300\" height=\"225\" />"}'; |
| 3186 | $content = wp_filter_content_tags( $content ); |
| 3187 | $this->assertStringNotContainsString( ' decoding="async"', $content ); |
| 3188 | } |
| 3189 | |
3165 | 3190 | /** |
3166 | 3191 | * @ticket 50756 |
3167 | 3192 | */ |