Media: Add "loading" as an allowed kses image attribute

With loading="lazy" being added to all images in [47554], let's ensure that it passes kses attributes too.

Fixes #50731.
Props TimothyBlynJacobs, peterwilsoncc, azaozz. 



git-svn-id: https://develop.svn.wordpress.org/trunk@48572 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jake Spurlock 2020-07-23 00:42:48 +00:00
parent e306fca2c1
commit 447d25f090
2 changed files with 28 additions and 0 deletions

View File

@ -230,6 +230,7 @@ if ( ! CUSTOM_TAGS ) {
'border' => true,
'height' => true,
'hspace' => true,
'loading' => true,
'longdesc' => true,
'vspace' => true,
'src' => true,

View File

@ -765,6 +765,11 @@ EOF;
'src="mypic.jpg"',
'src="mypic.jpg"',
),
array(
'img',
'loading="lazy"',
'loading="lazy"',
),
array(
'img',
'onerror=alert(1)',
@ -1352,4 +1357,26 @@ EOF;
),
);
}
/**
* Test filtering a standard img tag.
*
* @ticket 50731
*/
function test_wp_kses_img_tag_standard_attributes() {
$html = array(
'<img',
'loading="lazy"',
'src="https://example.com/img.jpg"',
'width="1000"',
'height="1000"',
'alt=""',
'class="wp-image-1000"',
'/>',
);
$html = implode( ' ', $html );
$this->assertSame( $html, wp_kses_post( $html ) );
}
}