Skip to content

Commit f8249c1

Browse files
authored
Merge pull request #7487 from ampproject/fix/complex-css-values
Fix failure to parse complex CSS values
2 parents faf3733 + 27856a7 commit f8249c1

File tree

4 files changed

+55
-15
lines changed

4 files changed

+55
-15
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"ampproject/amp-toolbox": "0.11.3",
1818
"cweagans/composer-patches": "~1.0",
1919
"fasterimage/fasterimage": "1.5.0",
20-
"sabberworm/php-css-parser": "8.4.0"
20+
"sabberworm/php-css-parser": "dev-master#cc791ad"
2121
},
2222
"require-dev": {
2323
"automattic/vipwpcs": "^2.2",
@@ -94,9 +94,9 @@
9494
"Remove 'match' keyword from uses <https://github.com/sebastianbergmann/phpunit/issues/4373>": "patches/remove-match-keyword.patch"
9595
},
9696
"sabberworm/php-css-parser": {
97-
"1. Add additional validation for size unit <https://github.com/sabberworm/PHP-CSS-Parser/pull/350>": "https://github.com/westonruter/PHP-CSS-Parser/commit/5b1d6a4abe43f4311d9b4674913ca665ed8c43aa.diff",
98-
"2. Validate name-start code points for identifier <https://github.com/westonruter/PHP-CSS-Parser/pull/2>": "https://github.com/westonruter/PHP-CSS-Parser/commit/9f96bc97fcb1e848a2f6ca6f658009996883dffc.diff",
99-
"3. Fix parsing CSS selectors which contain commas <https://github.com/westonruter/PHP-CSS-Parser/pull/1>": "https://github.com/westonruter/PHP-CSS-Parser/commit/dc18ba737fd6a611189a5b83729396500676f8dd.diff"
97+
"1. Validate name-start code points for identifier <https://github.com/westonruter/PHP-CSS-Parser/pull/2>": "https://github.com/sabberworm/PHP-CSS-Parser/compare/cc791ad...westonruter:PHP-CSS-Parser:fix/malformed-identifier-without-tests.diff",
98+
"2. Fix parsing CSS selectors which contain commas <https://github.com/westonruter/PHP-CSS-Parser/pull/1>": "https://github.com/sabberworm/PHP-CSS-Parser/compare/cc791ad...westonruter:PHP-CSS-Parser:fix/selector-comma-parsing-without-tests.diff",
99+
"3. Parse simple expressions <https://github.com/sabberworm/PHP-CSS-Parser/pull/389>": "https://github.com/sabberworm/PHP-CSS-Parser/compare/cc791ad...westonruter:PHP-CSS-Parser:fix/expression-parsing-without-tests.diff"
100100
}
101101
}
102102
},

composer.lock

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@ private function fetch_external_stylesheet( $url ) {
16581658
*/
16591659
private function get_parsed_stylesheet( $stylesheet, $options = [] ) {
16601660
$cached = true;
1661-
$cache_group = 'amp-parsed-stylesheet-v39'; // This should be bumped whenever the PHP-CSS-Parser is updated or parsed format is updated.
1661+
$cache_group = 'amp-parsed-stylesheet-v40'; // This should be bumped whenever the PHP-CSS-Parser is updated or parsed format is updated.
16621662
$use_transients = $this->should_use_transient_caching();
16631663

16641664
// @todo If ValidationExemption::is_px_verified_for_node( $this->current_node ) then keep !important.

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,44 @@ public function get_link_and_style_test_data() {
860860
],
861861
[],
862862
],
863+
'complex_css_values' => [
864+
'
865+
<html>
866+
<head>
867+
<style>
868+
body {
869+
background: green;
870+
width: calc((100vw - 100px) / 2);
871+
height: 100px;
872+
}
873+
</style>
874+
<style>
875+
:where(body) {
876+
width: min(var(--container-max-width), 100% - calc(var(--container-padding) * 2));
877+
margin-inline: auto;
878+
}
879+
</style>
880+
<style>
881+
body {
882+
--wp--preset--font-size--huge: 42px;
883+
--wp--preset--font-size--small: clamp(.875rem,.875rem + ((1vw - .48rem)*0.24),1rem);
884+
--wp--preset--font-size--medium: clamp(1rem,1rem + ((1vw - .48rem)*0.24),1.125rem);
885+
--wp--preset--font-size--large: clamp(1.5rem,1.5rem + ((1vw - .48rem)*0.24),1.625rem);
886+
--wp--preset--font-size--normal: 16px;
887+
}
888+
</style>
889+
</head>
890+
<body>
891+
</body>
892+
</html>
893+
',
894+
[
895+
'body{background:green;width:calc(( 100vw - 100px ) / 2);height:100px}',
896+
':where(body){width:min(var(--container-max-width),100% - calc(var(--container-padding) * 2));margin-inline:auto}',
897+
'body{--wp--preset--font-size--huge:42px;--wp--preset--font-size--small:clamp(.875rem,.875rem + ((1vw - .48rem) * .24),1rem);--wp--preset--font-size--medium:clamp(1rem,1rem + ((1vw - .48rem) * .24),1.125rem);--wp--preset--font-size--large:clamp(1.5rem,1.5rem + ((1vw - .48rem) * .24),1.625rem);--wp--preset--font-size--normal:16px}',
898+
],
899+
[],
900+
],
863901
];
864902
}
865903

0 commit comments

Comments
 (0)