Skip to content

Commit 80272f5

Browse files
committed
Only add layout attribute to AMP components
1 parent a7e0497 commit 80272f5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

includes/sanitizers/class-amp-layout-sanitizer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ class AMP_Layout_Sanitizer extends AMP_Base_Sanitizer {
2020
public function sanitize() {
2121
$xpath = new DOMXPath( $this->dom );
2222

23-
// Elements with the `layout` attribute will be validated by `AMP_Tag_And_Attribute_Sanitizer`.
24-
$nodes = $xpath->query( '//*[ not( @layout ) and ( @data-amp-layout or @width or @height or @style ) ]' );
23+
/**
24+
* Sanitize AMP nodes to be AMP compatible. Elements with the `layout` attribute will be validated by
25+
* `AMP_Tag_And_Attribute_Sanitizer`.
26+
*/
27+
$nodes = $xpath->query( '//*[ starts-with( name(), "amp-" ) and not( @layout ) and ( @data-amp-layout or @width or @height or @style ) ]' );
2528

2629
foreach ( $nodes as $node ) {
2730
/**

tests/php/test-amp-layout-sanitizer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class AMP_Layout_Sanitizer_Test extends WP_UnitTestCase {
1919
*/
2020
public function get_body_data() {
2121
return [
22+
'non_amp_component' => [
23+
'<svg height="10%" width="10%"></svg>',
24+
'<svg height="10%" width="10%"></svg>',
25+
],
26+
2227
'no_width_or_height' => [
2328
'<amp-img src="foo.jpg" data-amp-layout="fill"></amp-img>',
2429
'<amp-img src="foo.jpg" layout="fill"></amp-img>',

0 commit comments

Comments
 (0)