Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CSS Nesting] Fix parsing of nested at-rules with CSSOM
https://bugs.webkit.org/show_bug.cgi?id=255530
rdar://107760234

Reviewed by Antti Koivisto.

CSS OM insertion can "bypass" the normal stack by inserting at an arbitrarily
deeply nested context.
We already have isNestedContext() function to check for this, but it was
not used here unfortunately.

* LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/cssom-expected.txt:
* Source/WebCore/css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::consumeQualifiedRule):
(WebCore::CSSParserImpl::consumeRegularRuleList):
(WebCore::CSSParserImpl::consumeDeclarationListOrStyleBlockHelper):

Canonical link: https://commits.webkit.org/263028@main
  • Loading branch information
mdubet committed Apr 17, 2023
1 parent 3338c3a commit ab88221
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Expand Up @@ -6,8 +6,8 @@ PASS Simple CSSOM manipulation of subrules 3
PASS Simple CSSOM manipulation of subrules 4
PASS Simple CSSOM manipulation of subrules 5
PASS Simple CSSOM manipulation of subrules 6
FAIL Simple CSSOM manipulation of subrules 7 assert_equals: @supports is added expected ".a {\n color: red;\n & .b { color: green; }\n @supports selector(&) {\n & div { font-size: 10px; }\n}\n & .c { color: blue; }\n}" but got ".a {\n color: red;\n & .b { color: green; }\n @supports selector(&) {\n}\n & .c { color: blue; }\n}"
FAIL Simple CSSOM manipulation of subrules 8 assert_equals: color is changed, new rule is ignored expected ".a {\n color: olivedrab;\n & .b { color: green; }\n & .c { color: blue; }\n}" but got ".a {\n color: olivedrab;\n & .b { color: green; }\n @supports selector(&) {\n}\n & .c { color: blue; }\n}"
PASS Simple CSSOM manipulation of subrules 7
PASS Simple CSSOM manipulation of subrules 8
PASS Simple CSSOM manipulation of subrules 9
PASS Simple CSSOM manipulation of subrules 10
FAIL Simple CSSOM manipulation of subrules 11 assert_equals: invalid rule containing ampersand is kept in serialization expected ".a {\n :is(!& .foo, .b) { color: green; }\n}" but got ".a {\n :is(.b) { color: green; }\n}"
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/css/parser/CSSParserImpl.cpp
Expand Up @@ -416,7 +416,7 @@ RefPtr<StyleRuleBase> CSSParserImpl::consumeAtRule(CSSParserTokenRange& range, A
// https://drafts.csswg.org/css-syntax/#consume-a-qualified-rule
RefPtr<StyleRuleBase> CSSParserImpl::consumeQualifiedRule(CSSParserTokenRange& range, AllowedRulesType allowedRules)
{
auto isNestedStyleRule = [&]() {
auto isNestedStyleRule = [&] {
return isNestedContext() && allowedRules <= RegularRules;
};

Expand Down Expand Up @@ -581,7 +581,7 @@ Vector<RefPtr<StyleRuleBase>> CSSParserImpl::consumeRegularRuleList(CSSParserTok
{
Vector<RefPtr<StyleRuleBase>> rules;
if (isNestedContext()) {
runInNewNestingContext([&]() {
runInNewNestingContext([&] {
consumeStyleBlock(block, StyleRuleType::Style, ParsingStyleDeclarationsInRuleList::Yes);
if (!topContext().m_parsedProperties.isEmpty()) {
// This at-rule contains orphan declarations, we attach them to an implicit parent nesting rule. Web
Expand Down Expand Up @@ -1105,7 +1105,7 @@ RefPtr<StyleRuleBase> CSSParserImpl::consumeStyleRule(CSSParserTokenRange prelud
void CSSParserImpl::consumeDeclarationListOrStyleBlockHelper(CSSParserTokenRange range, StyleRuleType ruleType, OnlyDeclarations onlyDeclarations, ParsingStyleDeclarationsInRuleList isParsingStyleDeclarationsInRuleList)
{
auto nestedRulesAllowed = [&]() {
return m_styleRuleNestingDepth && context().cssNestingEnabled && onlyDeclarations == OnlyDeclarations::No;
return isNestedContext() && onlyDeclarations == OnlyDeclarations::No;
};

ASSERT(topContext().m_parsedProperties.isEmpty());
Expand Down

0 comments on commit ab88221

Please sign in to comment.