From 9ab408d9f63fd7a4c4dd3a4fe6bac7b883564fa5 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 30 Jun 2020 20:32:44 +0000 Subject: [PATCH] Media: Only add `loading` attribute to `img` tags using double quotes. Props azaozz. Fixes #50367. git-svn-id: https://develop.svn.wordpress.org/trunk@48239 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 4 ++-- tests/phpunit/tests/media.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index f9b41311c2..0dc67f7b86 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -1588,7 +1588,7 @@ function wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ) { $attr .= sprintf( ' sizes="%s"', esc_attr( $sizes ) ); } - // Add extra attributes to the image markup. + // Add the srcset and sizes attributes to the image markup. return preg_replace( '/]+?)[\/ ]*>/', '', $image ); } @@ -1737,7 +1737,7 @@ function wp_img_tag_add_loading_attr( $image, $context ) { } // Images should have source and dimension attributes for the `loading` attribute to be added. - if ( false === strpos( $image, ' src=' ) || false === strpos( $image, ' width=' ) || false === strpos( $image, ' height=' ) ) { + if ( false === strpos( $image, ' src="' ) || false === strpos( $image, ' width="' ) || false === strpos( $image, ' height="' ) ) { return $image; } diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 37b585d2a5..89b10be605 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -2683,6 +2683,16 @@ EOF; $this->assertNotContains( ' loading="lazy"', $img ); } + + /** + * @ticket 50367 + */ + function test_wp_img_tag_add_loading_attr_with_single_quotes() { + $img = " width="; + $img = wp_img_tag_add_loading_attr( $img, 'test' ); + + $this->assertNotContains( ' loading="lazy"', $img ); + } } /**