diff --git a/includes/sanitizers/class-amp-iframe-sanitizer.php b/includes/sanitizers/class-amp-iframe-sanitizer.php
index a2a3805631a..7b9cecb51e4 100644
--- a/includes/sanitizers/class-amp-iframe-sanitizer.php
+++ b/includes/sanitizers/class-amp-iframe-sanitizer.php
@@ -219,7 +219,7 @@ private function normalize_attributes( $attributes ) {
case 'allowfullscreen':
case 'allowtransparency':
- if ( 'false' !== $value ) {
+ if ( 'false' !== strtolower( $value ) ) {
$out[ $name ] = '';
}
break;
@@ -229,6 +229,16 @@ private function normalize_attributes( $attributes ) {
// Omit these since amp-iframe will add them if needed if the `allowfullscreen` attribute is present.
break;
+ case 'loading':
+ /*
+ * The `amp-iframe` component already does lazy-loading by default; trigger a validation error only
+ * if the value is not `lazy`.
+ */
+ if ( 'lazy' !== strtolower( $value ) ) {
+ $out[ $name ] = $value;
+ }
+ break;
+
default:
$out[ $name ] = $value;
break;
diff --git a/tests/php/test-amp-iframe-sanitizer.php b/tests/php/test-amp-iframe-sanitizer.php
index b62c5838ccb..584428db29a 100644
--- a/tests/php/test-amp-iframe-sanitizer.php
+++ b/tests/php/test-amp-iframe-sanitizer.php
@@ -43,7 +43,7 @@ public function get_data() {
],
'simple_iframe_without_noscript_or_placeholder' => [
- '',
+ '',
'',
[
'add_noscript_fallback' => false,
@@ -288,7 +288,7 @@ public function get_data() {
'attributes_removed_from_noscript_iframe' => [
'',
'
-
+
',
],
+
+ 'iframe_with_loading_lazy_attr' => [
+ '',
+ '
+
+
+ ',
+ ],
+
+ 'iframe_with_loading_eager_attr' => [
+ '',
+ '
+
+
+ ',
+ ],
];
}
@@ -434,9 +454,6 @@ public function test_converter( $source, $expected = null, $args = [] ) {
$sanitizer = new AMP_Iframe_Sanitizer( $dom, $args );
$sanitizer->sanitize();
- $whitelist_sanitizer = new AMP_Tag_And_Attribute_Sanitizer( $dom );
- $whitelist_sanitizer->sanitize();
-
$content = AMP_DOM_Utils::get_content_from_dom( $dom );
$this->assertEqualMarkup( $expected, $content );
}