Changeset 288111 in webkit


Ignore:
Timestamp:
Jan 17, 2022 11:57:43 PM (6 months ago)
Author:
Antti Koivisto
Message:

[:has() pseudo-class] Disallow nested :has()
https://bugs.webkit.org/show_bug.cgi?id=235231

Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

  • web-platform-tests/css/selectors/has-argument-with-explicit-scope.tentative-expected.txt:
  • web-platform-tests/css/selectors/has-basic-expected.txt:
  • web-platform-tests/css/selectors/parsing/parse-has-expected.txt:

Source/WebCore:

Nested case ':has(:has(foo))' adds no meaningful capability and would complicate invalidation.
See https://github.com/w3c/csswg-drafts/issues/6952 for more details.

  • css/parser/CSSSelectorParser.cpp:

(WebCore::CSSSelectorParser::consumePseudo):

Also set m_resistDefaultNamespace like other logical combination pseudo-classes.

  • css/parser/CSSSelectorParser.h:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r288107 r288111  
     12022-01-17  Antti Koivisto  <antti@apple.com>
     2
     3        [:has() pseudo-class] Disallow nested :has()
     4        https://bugs.webkit.org/show_bug.cgi?id=235231
     5
     6        Reviewed by Dean Jackson.
     7
     8        * web-platform-tests/css/selectors/has-argument-with-explicit-scope.tentative-expected.txt:
     9        * web-platform-tests/css/selectors/has-basic-expected.txt:
     10        * web-platform-tests/css/selectors/parsing/parse-has-expected.txt:
     11
    1122022-01-17  Myles C. Maxfield  <mmaxfield@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/has-basic-expected.txt

    r285921 r288111  
    1010PASS .parent:has(:is(.target ~ .sibling .descendant)) matches expected elements
    1111PASS .sibling:has(.descendant) ~ .target matches expected elements
    12 PASS :has(.sibling:has(.descendant) ~ .target) matches expected elements
    13 PASS :has(.sibling:has(.descendant) ~ .target) ~ .parent > .descendant matches expected elements
     12FAIL :has(.sibling:has(.descendant) ~ .target) matches expected elements The string did not match the expected pattern.
     13FAIL :has(.sibling:has(.descendant) ~ .target) ~ .parent > .descendant matches expected elements The string did not match the expected pattern.
    1414PASS :has(> .parent) matches expected elements
    1515PASS :has(> .target) matches expected elements
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/has-relative-argument-expected.txt

    r285921 r288111  
    3333PASS .y:has(> .g .h) .i matches expected elements
    3434PASS .y:has(.g .h) .i matches expected elements
    35 PASS .x:has(+ .y:has(> .g .h) .i) matches expected elements
    36 PASS .x:has(+ .y:has(.g .h) .i) matches expected elements
    37 PASS .x:has(+ .y:has(> .g .h) .i) ~ .j matches expected elements
    38 PASS .x:has(+ .y:has(.g .h) .i) ~ .j matches expected elements
    39 PASS .x:has(~ .y:has(> .g .h) .i) matches expected elements
    40 PASS .x:has(~ .y:has(.g .h) .i) matches expected elements
     35FAIL .x:has(+ .y:has(> .g .h) .i) matches expected elements The string did not match the expected pattern.
     36FAIL .x:has(+ .y:has(.g .h) .i) matches expected elements The string did not match the expected pattern.
     37FAIL .x:has(+ .y:has(> .g .h) .i) ~ .j matches expected elements The string did not match the expected pattern.
     38FAIL .x:has(+ .y:has(.g .h) .i) ~ .j matches expected elements The string did not match the expected pattern.
     39FAIL .x:has(~ .y:has(> .g .h) .i) matches expected elements The string did not match the expected pattern.
     40FAIL .x:has(~ .y:has(.g .h) .i) matches expected elements The string did not match the expected pattern.
    4141PASS .d .x:has(.e) matches expected elements
    4242PASS .d ~ .x:has(~ .e) matches expected elements
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/parsing/parse-has-expected.txt

    r285921 r288111  
    1616PASS ".a .b:has(.c .d)" should be a valid selector
    1717PASS ".a .b:has(.c .d) .e" should be a valid selector
    18 PASS ".a:has(.b:has(.c))" should be a valid selector
     18FAIL ".a:has(.b:has(.c))" should be a valid selector The string did not match the expected pattern.
    1919PASS ".a:has(.b:is(.c .d))" should be a valid selector
    20 PASS ".a:has(.b:is(.c:has(.d) .e))" should be a valid selector
     20FAIL ".a:has(.b:is(.c:has(.d) .e))" should be a valid selector assert_equals: serialization should be canonical expected ".a:has(.b:is(.c:has(.d) .e))" but got ".a:has(.b:is())"
    2121PASS ".a:is(.b:has(.c) .d)" should be a valid selector
    2222PASS ".a:not(:has(.b))" should be a valid selector
  • trunk/Source/WebCore/ChangeLog

    r288110 r288111  
     12022-01-17  Antti Koivisto  <antti@apple.com>
     2
     3        [:has() pseudo-class] Disallow nested :has()
     4        https://bugs.webkit.org/show_bug.cgi?id=235231
     5
     6        Reviewed by Dean Jackson.
     7
     8        Nested case ':has(:has(foo))' adds no meaningful capability and would complicate invalidation.
     9        See https://github.com/w3c/csswg-drafts/issues/6952 for more details.
     10
     11        * css/parser/CSSSelectorParser.cpp:
     12        (WebCore::CSSSelectorParser::consumePseudo):
     13
     14        Also set m_resistDefaultNamespace like other logical combination pseudo-classes.
     15
     16        * css/parser/CSSSelectorParser.h:
     17
    1182022-01-17  Youenn Fablet  <youenn@apple.com>
    219
  • trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp

    r287222 r288111  
    687687        switch (selector->pseudoClassType()) {
    688688        case CSSSelector::PseudoClassNot: {
    689             SetForScope<bool> resistDefaultNamespace(m_resistDefaultNamespace, true);
     689            SetForScope resistDefaultNamespace(m_resistDefaultNamespace, true);
    690690            auto selectorList = makeUnique<CSSSelectorList>();
    691691            *selectorList = consumeComplexSelectorList(block);
     
    735735        case CSSSelector::PseudoClassMatches:
    736736        case CSSSelector::PseudoClassAny: {
    737             SetForScope<bool> resistDefaultNamespace(m_resistDefaultNamespace, true);
     737            SetForScope resistDefaultNamespace(m_resistDefaultNamespace, true);
    738738            auto selectorList = makeUnique<CSSSelectorList>();
    739739            *selectorList = consumeForgivingComplexSelectorList(block);
     
    752752        }
    753753        case CSSSelector::PseudoClassHas: {
     754            if (m_disallowHasPseudoClass)
     755                return nullptr;
     756            SetForScope resistDefaultNamespace(m_resistDefaultNamespace, true);
     757            SetForScope disallowNestedHas(m_disallowHasPseudoClass, true);
    754758            auto selectorList = makeUnique<CSSSelectorList>();
    755759            *selectorList = consumeForgivingRelativeSelectorList(block);
  • trunk/Source/WebCore/css/parser/CSSSelectorParser.h

    r285054 r288111  
    9090    bool m_failedParsing { false };
    9191    bool m_disallowPseudoElements { false };
     92    bool m_disallowHasPseudoClass { false };
    9293    bool m_resistDefaultNamespace { false };
    9394    bool m_ignoreDefaultNamespace { false };
Note: See TracChangeset for help on using the changeset viewer.