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
This commit is contained in:
Felix Arntz 2020-06-30 20:32:44 +00:00
parent a21b3b7d36
commit 9ab408d9f6
2 changed files with 12 additions and 2 deletions

View File

@ -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( '/<img ([^>]+?)[\/ ]*>/', '<img $1' . $attr . ' />', $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;
}

View File

@ -2683,6 +2683,16 @@ EOF;
$this->assertNotContains( ' loading="lazy"', $img );
}
/**
* @ticket 50367
*/
function test_wp_img_tag_add_loading_attr_with_single_quotes() {
$img = "<img src='example.png' alt=' width='300' height='225' />";
$img = wp_img_tag_add_loading_attr( $img, 'test' );
$this->assertNotContains( ' loading="lazy"', $img );
}
}
/**