Skip to content

Commit

Permalink
Merge pull request #7644 from ampproject/update/img-sanitizer
Browse files Browse the repository at this point in the history
Update `AMP_Img_Sanitizer` to avoid adding `fetchpriority` attr to `amp-img`
  • Loading branch information
westonruter authored Oct 25, 2023
2 parents a2d8418 + 1df48d7 commit d9727b6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ext-json": "*",
"ext-libxml": "*",
"ext-spl": "*",
"ampproject/amp-toolbox": "0.11.3",
"ampproject/amp-toolbox": "dev-main",
"cweagans/composer-patches": "^1.0",
"fasterimage/fasterimage": "1.5.0",
"sabberworm/php-css-parser": "dev-master#cc791ad"
Expand Down
18 changes: 10 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions includes/sanitizers/class-amp-img-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ private function filter_attributes( $attributes ) {
}
break;

// Avoid adding `fetchpriority` to amp-img element.
case Attribute::FETCHPRIORITY:
break;

default:
$out[ $name ] = $value;
break;
Expand Down
21 changes: 21 additions & 0 deletions tests/php/test-amp-img-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,27 @@ public function get_data() {
'native_img_used' => false,
],
],

'fetchpriority_attr_not_added_to_amp-img' => [
'<img width="825" height="510" src="https://placehold.it/825x510" fetchpriority="high">',
'<amp-img width="825" height="510" src="https://placehold.it/825x510" class="amp-wp-enforced-sizes" layout="intrinsic"></amp-img>',
[
'add_noscript_fallback' => false,
],
],

'fetchpriority_attr_is_preserved_in_noscript_fallback_img' => [
'<img width="825" height="510" src="https://placehold.it/825x510" fetchpriority="high">',
'<amp-img width="825" height="510" src="https://placehold.it/825x510" class="amp-wp-enforced-sizes" layout="intrinsic"><noscript><img width="825" height="510" src="https://placehold.it/825x510" fetchpriority="high"></noscript></amp-img>',
],

'fetchpriority_attr_is_preserved_in_native_img' => [
'<img width="825" height="510" src="https://placehold.it/825x510" fetchpriority="high">',
'<img width="825" height="510" src="https://placehold.it/825x510" fetchpriority="high" decoding="async" class="amp-wp-enforced-sizes">',
[
'native_img_used' => true,
],
],
];
}

Expand Down

0 comments on commit d9727b6

Please sign in to comment.