Skip to content

Commit 3b0b45a

Browse files
authored
Merge pull request #6312 from ampproject/try/reduce-specificity-hack-size
Reduce length of specificity-hacked CSS selectors
2 parents 6035d35 + 70fcaeb commit 3b0b45a

File tree

7 files changed

+56
-49
lines changed

7 files changed

+56
-49
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ private function fetch_external_stylesheet( $url ) {
16561656
*/
16571657
private function get_parsed_stylesheet( $stylesheet, $options = [] ) {
16581658
$cached = true;
1659-
$cache_group = 'amp-parsed-stylesheet-v38'; // This should be bumped whenever the PHP-CSS-Parser is updated or parsed format is updated.
1659+
$cache_group = 'amp-parsed-stylesheet-v39'; // This should be bumped whenever the PHP-CSS-Parser is updated or parsed format is updated.
16601660
$use_transients = $this->should_use_transient_caching();
16611661

16621662
// @todo If ValidationExemption::is_px_verified_for_node( $this->current_node ) then keep !important.
@@ -2928,16 +2928,15 @@ static function( Selector $old_selector ) {
29282928
if ( $old_selector->getSpecificity() % 10 > 0 ) {
29292929
$specificity_multiplier++;
29302930
}
2931-
$selector_mod = str_repeat( ':not(#_)', $specificity_multiplier ); // Here "_" is just a short single-char ID.
29322931

29332932
$new_selector = $old_selector->getSelector();
29342933

2935-
// Amend the selector mod to the first element in selector if it is already the root; otherwise add new root ancestor.
2936-
if ( preg_match( '/^\s*(html|:root)\b/i', $new_selector, $matches ) ) {
2937-
$new_selector = substr( $new_selector, 0, strlen( $matches[0] ) ) . $selector_mod . substr( $new_selector, strlen( $matches[0] ) );
2934+
if ( '#_)' === substr( $new_selector, -3 ) ) {
2935+
$new_selector = rtrim( $new_selector, ')' ) . str_repeat( '#_', $specificity_multiplier ) . ')';
29382936
} else {
2939-
$new_selector = sprintf( ':root%s %s', $selector_mod, $new_selector );
2937+
$new_selector .= ':not(' . str_repeat( '#_', $specificity_multiplier ) . ')'; // Here "_" is just a short single-char ID.
29402938
}
2939+
29412940
return new Selector( $new_selector );
29422941
},
29432942
$ruleset->getSelectors()
@@ -2986,9 +2985,9 @@ private function collect_inline_styles( DOMElement $element ) {
29862985
return;
29872986
}
29882987

2989-
$class = 'amp-wp-' . substr( md5( $value ), 0, 7 );
2990-
$root = ':root' . str_repeat( ':not(#_)', self::INLINE_SPECIFICITY_MULTIPLIER );
2991-
$rule = sprintf( '%s .%s { %s }', $root, $class, $value );
2988+
$class = 'amp-wp-' . substr( md5( $value ), 0, 7 );
2989+
$specificity = ':not(' . str_repeat( '#_', self::INLINE_SPECIFICITY_MULTIPLIER ) . ')';
2990+
$rule = sprintf( '.%s%s{%s}', $class, $specificity, $value );
29922991

29932992
$this->set_current_node( $element ); // And sources when needing to be located.
29942993

includes/validation/class-amp-validated-url-post-type.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,6 +2812,14 @@ static function ( $a, $b ) use ( $stylesheets ) {
28122812
$selector_html
28132813
);
28142814
}
2815+
$selector_html = preg_replace(
2816+
'/:not\((#_)+\)/',
2817+
sprintf(
2818+
'<abbr title="%s">$0</abbr>',
2819+
esc_attr__( 'Pseudo-class selector used to increase specificity for rule extracted from inline styles and/or properties with !important qualifiers.', 'amp' )
2820+
),
2821+
$selector_html
2822+
);
28152823

28162824
echo $selector_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
28172825

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function get_sanitizer_data() {
8080
<html>
8181
<head>
8282
<meta charset="utf-8">
83-
<style amp-custom>#my-accordion{display:block;outline:solid 2px red}amp-accordion#my-accordion{outline:solid 2px green}amp-accordion h2{text-transform:uppercase}:root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-a33452e{border:solid 1px black}
83+
<style amp-custom>#my-accordion{display:block;outline:solid 2px red}amp-accordion#my-accordion{outline:solid 2px green}amp-accordion h2{text-transform:uppercase}.amp-wp-a33452e:not(#_#_#_#_#_){border:solid 1px black}
8484
8585
/*# sourceURL="amp-custom.css" */</style>
8686
</head>
@@ -245,7 +245,7 @@ public function get_sanitizer_data() {
245245
<script type="module" async="" src="https://cdn.ampproject.org/v0/bento-marquee-1.0.mjs" data-px-verified-tag></script>
246246
<script nomodule="" async="" src="https://cdn.ampproject.org/v0/bento-marquee-1.0.js" data-px-verified-tag></script>
247247
<link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/bento-marquee-1.0.css" data-px-verified-tag data-px-verified-attrs="href">
248-
<style amp-custom>#timeago{color:red}amp-timeago#timeago{color:blue}#marquee{display:block;outline:solid 2px red}bento-marquee#marquee{outline:solid 2px green}bento-marquee h2{text-transform:uppercase}:root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-c437205{border:solid 1px green}:root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-4d7586b{max-width:50vw}:root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-4ce7767{position:relative;width:100%;height:400px}
248+
<style amp-custom>#timeago{color:red}amp-timeago#timeago{color:blue}#marquee{display:block;outline:solid 2px red}bento-marquee#marquee{outline:solid 2px green}bento-marquee h2{text-transform:uppercase}.amp-wp-c437205:not(#_#_#_#_#_){border:solid 1px green}.amp-wp-4d7586b:not(#_#_#_#_#_){max-width:50vw}.amp-wp-4ce7767:not(#_#_#_#_#_){position:relative;width:100%;height:400px}
249249
250250
/*# sourceURL="amp-custom.css" */</style>
251251
</head>
@@ -415,7 +415,7 @@ public function get_sanitizer_data() {
415415
<html>
416416
<head>
417417
<meta charset="utf-8">
418-
<style amp-custom>:root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-3ef80bd{height:40px}:root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-120213e{height:40px;width:147px}
418+
<style amp-custom>.amp-wp-3ef80bd:not(#_#_#_#_#_){height:40px}.amp-wp-120213e:not(#_#_#_#_#_){height:40px;width:147px}
419419
420420
/*# sourceURL="amp-custom.css" */</style>
421421
</head>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ function ( Element $element ) {
594594
$this->assertStringContainsString( '}amp-audio{', $css_text );
595595
break;
596596
case 3:
597-
$this->assertStringContainsString( ':not(#_) amp-audio{', $css_text );
597+
$this->assertStringContainsString( '}amp-audio:not(#_', $css_text );
598598
break;
599599
}
600600

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function get_body_style_attribute_data() {
7272
'<span style="color: #00ff00;">This is green.</span>',
7373
'<span data-amp-original-style="color: #00ff00;" class="amp-wp-bb01159">This is green.</span>',
7474
[
75-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-bb01159{color:#0f0}',
75+
'.amp-wp-bb01159:not(#_#_#_#_#_){color:#0f0}',
7676
],
7777
],
7878

@@ -86,81 +86,81 @@ public function get_body_style_attribute_data() {
8686
'<span style="color : #00ff00">This is green.</span>',
8787
'<span data-amp-original-style="color : #00ff00" class="amp-wp-0837823">This is green.</span>',
8888
[
89-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-0837823{color:#0f0}',
89+
'.amp-wp-0837823:not(#_#_#_#_#_){color:#0f0}',
9090
],
9191
],
9292

9393
'span_two_styles_reversed' => [
9494
'<span style="color: #00ff00; background-color: #000;">This is green.</span>',
9595
'<span data-amp-original-style="color: #00ff00; background-color: #000;" class="amp-wp-be0c539">This is green.</span>',
9696
[
97-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-be0c539{color:#0f0;background-color:#000}',
97+
'.amp-wp-be0c539:not(#_#_#_#_#_){color:#0f0;background-color:#000}',
9898
],
9999
],
100100

101101
'span_display_none' => [
102102
'<span style="display: none;">Kses-banned properties are allowed since Kses will have already applied if user does not have unfiltered_html.</span>',
103103
'<span data-amp-original-style="display: none;" class="amp-wp-224b51a">Kses-banned properties are allowed since Kses will have already applied if user does not have unfiltered_html.</span>',
104104
[
105-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-224b51a{display:none}',
105+
'.amp-wp-224b51a:not(#_#_#_#_#_){display:none}',
106106
],
107107
],
108108

109109
'!important_is_ok' => [
110110
'<span style="padding:1px; margin: 2px !important; outline: 3px;">!important is converted.</span>',
111111
'<span data-amp-original-style="padding:1px; margin: 2px !important; outline: 3px;" class="amp-wp-6a75598">!important is converted.</span>',
112112
[
113-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-6a75598{padding:1px;outline:3px}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-6a75598{margin:2px}',
113+
'.amp-wp-6a75598:not(#_#_#_#_#_){padding:1px;outline:3px}.amp-wp-6a75598:not(#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_){margin:2px}',
114114
],
115115
],
116116

117117
'!important_with_spaces_also_converted' => [
118118
'<span style="color: red ! important;">!important is converted.</span>',
119119
'<span data-amp-original-style="color: red ! important;" class="amp-wp-952600b">!important is converted.</span>',
120120
[
121-
':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-952600b{color:red}',
121+
'.amp-wp-952600b:not(#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_){color:red}',
122122
],
123123
],
124124

125125
'!important_multiple_is_converted' => [
126126
'<span style="color: red !important; background: blue!important;">!important is converted.</span>',
127127
'<span data-amp-original-style="color: red !important; background: blue!important;" class="amp-wp-1e2bfaa">!important is converted.</span>',
128128
[
129-
':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-1e2bfaa{color:red;background:blue}',
129+
'.amp-wp-1e2bfaa:not(#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_){color:red;background:blue}',
130130
],
131131
],
132132

133133
'!important_takes_precedence_over_inline' => [
134134
'<header id="header" style="display: none;"><h1>This is the header.</h1></header><style>#header { display: block !important;width: 100%;background: #fff; }',
135135
'<header id="header" data-amp-original-style="display: none;" class="amp-wp-224b51a"><h1>This is the header.</h1></header>',
136136
[
137-
'#header{width:100%;background:#fff}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) #header{display:block}',
138-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-224b51a{display:none}',
137+
'#header{width:100%;background:#fff}#header:not(#_#_#_#_#_#_#_){display:block}',
138+
'.amp-wp-224b51a:not(#_#_#_#_#_){display:none}',
139139
],
140140
],
141141

142142
'two_nodes' => [
143143
'<span style="color: #00ff00;"><span style="color: #ff0000;">This is red.</span></span>',
144144
'<span data-amp-original-style="color: #00ff00;" class="amp-wp-bb01159"><span data-amp-original-style="color: #ff0000;" class="amp-wp-cc68ddc">This is red.</span></span>',
145145
[
146-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-bb01159{color:#0f0}',
147-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-cc68ddc{color:#f00}',
146+
'.amp-wp-bb01159:not(#_#_#_#_#_){color:#0f0}',
147+
'.amp-wp-cc68ddc:not(#_#_#_#_#_){color:#f00}',
148148
],
149149
],
150150

151151
'existing_class_attribute' => [
152152
'<figure class="alignleft" style="background: #000"></figure>',
153153
'<figure class="alignleft amp-wp-2864855" data-amp-original-style="background: #000"></figure>',
154154
[
155-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-2864855{background:#000}',
155+
'.amp-wp-2864855:not(#_#_#_#_#_){background:#000}',
156156
],
157157
],
158158

159159
'inline_style_element_with_multiple_rules_containing_selectors_is_removed' => [
160160
'<style>div > span { font-weight:bold !important; font-style: italic; } @media screen and ( max-width: 640px ) { div > span { font-weight:normal !important; font-style: normal; } }</style><div><span>bold!</span></div>',
161161
'<div><span>bold!</span></div>',
162162
[
163-
'div > span{font-style:italic}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) div > span{font-weight:bold}@media screen and ( max-width: 640px ){div > span{font-style:normal}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) div > span{font-weight:normal}}',
163+
'div > span{font-style:italic}div > span:not(#_#_#_#_#_#_#_#_){font-weight:bold}@media screen and ( max-width: 640px ){div > span{font-style:normal}div > span:not(#_#_#_#_#_#_#_#_){font-weight:normal}}',
164164
],
165165
],
166166

@@ -178,7 +178,7 @@ public function get_body_style_attribute_data() {
178178
'<span style="color:brown; @media screen { color:green }">invalid @-rule omitted.</span>',
179179
'<span data-amp-original-style="color:brown; @media screen { color:green }" class="amp-wp-481af57">invalid @-rule omitted.</span>',
180180
[
181-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-481af57{color:brown}',
181+
'.amp-wp-481af57:not(#_#_#_#_#_){color:brown}',
182182
],
183183
[],
184184
],
@@ -247,9 +247,9 @@ public function get_body_style_attribute_data() {
247247
'<style>#child {color:red !important} #parent #child {color:pink !important} .foo { color:blue !important; } #me .foo { color: green !important; }</style><div id="parent"><span id="child" class="foo bar baz">one</span><span style="color: yellow;">two</span><span style="color: purple !important;">three</span></div><div id="me"><span class="foo"></span></div>',
248248
'<div id="parent"><span id="child" class="foo bar baz">one</span><span data-amp-original-style="color: yellow;" class="amp-wp-64b4fd4">two</span><span data-amp-original-style="color: purple !important;" class="amp-wp-ab79d9e">three</span></div><div id="me"><span class="foo"></span></div>',
249249
[
250-
':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) #child{color:red}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) #parent #child{color:pink}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .foo{color:blue}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) #me .foo{color:green}',
251-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-64b4fd4{color:yellow}',
252-
':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-ab79d9e{color:purple}',
250+
'#child:not(#_#_#_#_#_#_#_){color:red}#parent #child:not(#_#_#_#_#_#_#_#_){color:pink}.foo:not(#_#_#_#_#_#_#_){color:blue}#me .foo:not(#_#_#_#_#_#_#_#_){color:green}',
251+
'.amp-wp-64b4fd4:not(#_#_#_#_#_){color:yellow}',
252+
'.amp-wp-ab79d9e:not(#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_){color:purple}',
253253
],
254254
],
255255

@@ -265,15 +265,15 @@ public function get_body_style_attribute_data() {
265265
'<table><colgroup><col width="253"/></colgroup></table>',
266266
'<table><colgroup><col data-amp-original-style="width: 253px" class="amp-wp-cbcb5c2"></colgroup></table>',
267267
[
268-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-cbcb5c2{width:253px}',
268+
'.amp-wp-cbcb5c2:not(#_#_#_#_#_){width:253px}',
269269
],
270270
],
271271

272272
'col_with_percent_width_attribute' => [
273273
'<table><colgroup><col width="50%"/></colgroup></table>',
274274
'<table><colgroup><col data-amp-original-style="width: 50%" class="amp-wp-cd7753e"></colgroup></table>',
275275
[
276-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-cd7753e{width:50%}',
276+
'.amp-wp-cd7753e:not(#_#_#_#_#_){width:50%}',
277277
],
278278
],
279279

@@ -288,7 +288,7 @@ public function get_body_style_attribute_data() {
288288
'<table><colgroup><col width="50" style="background-color: red; width: 60px"/></colgroup></table>',
289289
'<table><colgroup><col data-amp-original-style="width: 50px;background-color: red; width: 60px" class="amp-wp-c8aa9e9"></colgroup></table>',
290290
[
291-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-c8aa9e9{width:50px;width:60px;background-color:red}',
291+
'.amp-wp-c8aa9e9:not(#_#_#_#_#_){width:50px;width:60px;background-color:red}',
292292
],
293293
],
294294

@@ -352,8 +352,8 @@ public function get_body_style_attribute_data() {
352352
',
353353
[
354354
'.custom-population{color:red}',
355-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-f2a1aff{color:blue}',
356-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-d4ea4c7{outline:solid 1px black}',
355+
'.amp-wp-f2a1aff:not(#_#_#_#_#_){color:blue}',
356+
'.amp-wp-d4ea4c7:not(#_#_#_#_#_){outline:solid 1px black}',
357357
],
358358
],
359359
'with_mustache_template_script' => [
@@ -386,8 +386,8 @@ public function get_body_style_attribute_data() {
386386
',
387387
[
388388
'.custom-population{color:red}',
389-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-f2a1aff{color:blue}',
390-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-d4ea4c7{outline:solid 1px black}',
389+
'.amp-wp-f2a1aff:not(#_#_#_#_#_){color:blue}',
390+
'.amp-wp-d4ea4c7:not(#_#_#_#_#_){outline:solid 1px black}',
391391
],
392392
],
393393
'with_internal_amp_selectors_and_class_names' => [
@@ -531,9 +531,9 @@ public function get_link_and_style_test_data() {
531531
'multiple_amp_custom_and_other_styles' => [
532532
'<html amp><head><meta charset="utf-8"><style amp-custom>b {color:red !important}</style><style amp-custom>i {color:blue}</style><style type="text/css">u {color:green; text-decoration: underline !important}</style></head><body><style>s {color:yellow} /* So !important! */</style><b>1</b><i>i</i><u>u</u><s>s</s></body></html>',
533533
[
534-
':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) b{color:red}',
534+
'b:not(#_#_#_#_#_#_#_#_){color:red}',
535535
'i{color:blue}',
536-
'u{color:green}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) u{text-decoration:underline}',
536+
'u{color:green}u:not(#_#_#_#_#_#_#_#_){text-decoration:underline}',
537537
's{color:yellow}',
538538
],
539539
[],
@@ -547,7 +547,7 @@ public function get_link_and_style_test_data() {
547547
'strong.before-dashicon',
548548
'.dashicons-dashboard:before',
549549
'strong.after-dashicon',
550-
':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) s{color:yellow}',
550+
's:not(#_#_#_#_#_#_#_#_){color:yellow}',
551551
],
552552
[],
553553
],
@@ -575,8 +575,8 @@ public function get_link_and_style_test_data() {
575575
'style_on_root_element' => [
576576
'<html amp style="color:red;"><head><meta charset="utf-8"><style amp-custom>html { background-color: blue !important; }</style></head><body>Hi</body></html>',
577577
[
578-
'html:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_){background-color:blue}',
579-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-10b06ba{color:red}',
578+
'html:not(#_#_#_#_#_#_#_#_){background-color:blue}',
579+
'.amp-wp-10b06ba:not(#_#_#_#_#_){color:red}',
580580
],
581581
[],
582582
],
@@ -1099,10 +1099,10 @@ public function get_data_to_test_transform_important_qualifiers_arg() {
10991099
true, // should_sanitize
11001100
$html,
11011101
[
1102-
':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .foo{color:red}',
1103-
':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .foo[data-amp-original-style*="blue"]{outline:solid 2px green}',
1104-
':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-9605c4d{background:blue}',
1105-
':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-32bb249{background:red}',
1102+
'.foo:not(#_#_#_#_#_#_#_){color:red}',
1103+
'.foo[data-amp-original-style*="blue"]:not(#_#_#_#_#_#_#_){outline:solid 2px green}',
1104+
'.amp-wp-9605c4d:not(#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_){background:blue}',
1105+
'.amp-wp-32bb249:not(#_#_#_#_#_){background:red}',
11061106
],
11071107
'<style amp-custom>',
11081108
'

tests/php/test-class-amp-content-sanitizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function test_sanitize_document() {
3838
$sanitize_results['scripts']
3939
);
4040
$this->assertEquals(
41-
[ ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-9f6e771{outline:solid 1px red}' ],
41+
[ '.amp-wp-9f6e771:not(#_#_#_#_#_){outline:solid 1px red}' ],
4242
$sanitize_results['stylesheets']
4343
);
4444
$this->assertEmpty( $sanitize_results['styles'] );
@@ -74,7 +74,7 @@ public function test_sanitize_all() {
7474
$expected_return = [
7575
'<amp-video src="https://example.com/foo.mp4" width="100" height="200" layout="intrinsic" data-amp-original-style="outline: solid 1px red;" class="amp-wp-9f6e771"><a href="https://example.com/foo.mp4" fallback="">https://example.com/foo.mp4</a><noscript><video src="https://example.com/foo.mp4" width="100" height="200"></video></noscript></amp-video>',
7676
[ 'amp-video' => true ],
77-
[ ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-9f6e771{outline:solid 1px red}' ],
77+
[ '.amp-wp-9f6e771:not(#_#_#_#_#_){outline:solid 1px red}' ],
7878
];
7979

8080
$actual_return = AMP_Content_Sanitizer::sanitize(

0 commit comments

Comments
 (0)