Skip to content

Commit

Permalink
[:has() pseudo-class] Use unforgiving parsing for selector list
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=249914
rdar://103733208

Reviewed by Antti Koivisto.

Following CSSWG resolution: w3c/csswg-drafts#7676 (comment)

In order to unbreak jQuery.

* LayoutTests/imported/w3c/web-platform-tests/css/selectors/parsing/parse-has-expected.txt:
* Source/WebCore/css/parser/CSSSelectorParser.cpp:
(WebCore::CSSSelectorParser::consumeRelativeSelectorList):
(WebCore::CSSSelectorParser::consumePseudo):
(WebCore::CSSSelectorParser::consumeForgivingRelativeSelectorList): Deleted.
* Source/WebCore/css/parser/CSSSelectorParser.h:

Canonical link: https://commits.webkit.org/258712@main
  • Loading branch information
nt1m committed Jan 10, 2023
1 parent f0f68a8 commit 2eca427
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ PASS ".a:has" should be an invalid selector
PASS ".a:has b" should be an invalid selector
PASS ":has()" should be an invalid selector
PASS ":has(123)" should be an invalid selector
FAIL ":has(.a, 123)" should be an invalid selector assert_throws_dom: ":has(.a, 123)" should throw in querySelector function "() => document.querySelector(selector)" did not throw
PASS ":has(.a, 123)" should be an invalid selector
PASS ":has(:is(.a, 123))" should be a valid selector

16 changes: 8 additions & 8 deletions Source/WebCore/css/parser/CSSSelectorParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ CSSSelectorList CSSSelectorParser::consumeComplexSelectorList(CSSParserTokenRang
});
}

CSSSelectorList CSSSelectorParser::consumeRelativeSelectorList(CSSParserTokenRange& range)
{
return consumeSelectorList(range, [&](CSSParserTokenRange& range) {
return consumeRelativeScopeSelector(range);
});
}

CSSSelectorList CSSSelectorParser::consumeNestedSelectorList(CSSParserTokenRange& range)
{
return consumeSelectorList(range, [&] (CSSParserTokenRange& range) {
Expand Down Expand Up @@ -155,13 +162,6 @@ CSSSelectorList CSSSelectorParser::consumeForgivingComplexSelectorList(CSSParser
});
}

CSSSelectorList CSSSelectorParser::consumeForgivingRelativeSelectorList(CSSParserTokenRange& range)
{
return consumeForgivingSelectorList(range, [&](CSSParserTokenRange& range) {
return consumeRelativeScopeSelector(range);
});
}

bool CSSSelectorParser::supportsComplexSelector(CSSParserTokenRange range, const CSSParserContext& context)
{
range.consumeWhitespace();
Expand Down Expand Up @@ -830,7 +830,7 @@ std::unique_ptr<CSSParserSelector> CSSSelectorParser::consumePseudo(CSSParserTok
SetForScope resistDefaultNamespace(m_resistDefaultNamespace, true);
SetForScope disallowNestedHas(m_disallowHasPseudoClass, true);
auto selectorList = makeUnique<CSSSelectorList>();
*selectorList = consumeForgivingRelativeSelectorList(block);
*selectorList = consumeRelativeSelectorList(block);
if (selectorList->isEmpty() || !block.atEnd())
return nullptr;
selector->setSelectorList(WTFMove(selectorList));
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/parser/CSSSelectorParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class CSSSelectorParser {
template<typename ConsumeSelector> CSSSelectorList consumeForgivingSelectorList(CSSParserTokenRange&, ConsumeSelector&&);

CSSSelectorList consumeForgivingComplexSelectorList(CSSParserTokenRange&);
CSSSelectorList consumeForgivingRelativeSelectorList(CSSParserTokenRange&);
CSSSelectorList consumeCompoundSelectorList(CSSParserTokenRange&);
CSSSelectorList consumeRelativeSelectorList(CSSParserTokenRange&);

std::unique_ptr<CSSParserSelector> consumeComplexSelector(CSSParserTokenRange&);
std::unique_ptr<CSSParserSelector> consumeCompoundSelector(CSSParserTokenRange&);
Expand Down

0 comments on commit 2eca427

Please sign in to comment.