Skip to content

Commit

Permalink
Fix collection of noscript-allowed attributes (#7036)
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Apr 11, 2022
1 parent 0850244 commit 07f0f24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions includes/sanitizers/trait-amp-noscript-fallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use AmpProject\Dom\Document;
use AmpProject\Html\Attribute;
use AmpProject\Html\Tag;

/**
* Trait AMP_Noscript_Fallback
Expand Down Expand Up @@ -43,6 +44,15 @@ protected function initialize_noscript_allowed_attributes( $tag ) {
);

foreach ( AMP_Allowed_Tags_Generated::get_allowed_tag( $tag ) as $tag_spec ) { // Normally 1 iteration.
if (
! (
( isset( $tag_spec['tag_spec']['mandatory_ancestor'] ) && Tag::NOSCRIPT === $tag_spec['tag_spec']['mandatory_ancestor'] )
||
( isset( $tag_spec['tag_spec']['mandatory_parent'] ) && Tag::NOSCRIPT === $tag_spec['tag_spec']['mandatory_parent'] )
)
) {
continue;
}
foreach ( $tag_spec['attr_spec_list'] as $attr_name => $attr_spec ) {
$this->noscript_fallback_allowed_attributes[ $attr_name ] = true;
if ( isset( $attr_spec['alternative_names'] ) ) {
Expand Down
9 changes: 9 additions & 0 deletions tests/php/test-amp-img-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,15 @@ public function get_data() {
'<img height="1" width="1" style="display:none" alt="fbpx" src="https://facebook.com/tr?id=123456789012345&ev=PageView&noscript=1" referrerpolicy="no-referrer">',
'<amp-pixel src="https://facebook.com/tr?id=123456789012345&amp;ev=PageView&amp;noscript=1" layout="nodisplay" referrerpolicy="no-referrer"></amp-pixel>',
],


'hero_img_with_noscript_fallback' => [
'<img data-hero width="825" height="510" src="https://placehold.it/825x510" srcset="http://placehold.it/1024x768 1024w" sizes="(max-width: 600px) 825px, 1024px" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="">',
'<amp-img data-hero width="825" height="510" src="https://placehold.it/825x510" srcset="http://placehold.it/1024x768 1024w" sizes="(max-width: 600px) 825px, 1024px" class="attachment-post-thumbnail size-post-thumbnail wp-post-image amp-wp-enforced-sizes" alt layout="intrinsic" disable-inline-width><noscript><img width="825" height="510" src="https://placehold.it/825x510" srcset="http://placehold.it/1024x768 1024w" sizes="(max-width: 600px) 825px, 1024px" alt></noscript></amp-img>',
[
'native_img_used' => false,
],
],
];
}

Expand Down

0 comments on commit 07f0f24

Please sign in to comment.