Changeset 270955 in webkit


Ignore:
Timestamp:
Dec 17, 2020 3:21:58 PM (19 months ago)
Author:
Manuel Rego Casasnovas
Message:

[selectors] Default namespace gets ignored inside non-type selectors for :is() and :not()
https://bugs.webkit.org/show_bug.cgi?id=219950

Reviewed by Antti Koivisto.

Source/WebCore:

Based on Blink r820500 and r820557 by <andruud@chromium.org>.

Default namespace declarations do not affect the compound selector
representing the subject of any selector within a :is() or :not() pseudo-class,
unless that compound selector contains an explicit universal selector or type selector.
Spec: https://drafts.csswg.org/selectors-4/#matches

This patch aligns WebKit implementation with Chromium and Firefox, so two WPT tests pass now.

  • css/parser/CSSSelectorParser.cpp:

(WebCore::atEndIgnoringWhitespace):
(WebCore::CSSSelectorParser::consumeCompoundSelector):
(WebCore::CSSSelectorParser::consumePseudo):
(WebCore::CSSSelectorParser::defaultNamespace const):

  • css/parser/CSSSelectorParser.h:

LayoutTests:

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r270950 r270955  
     12020-12-17  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [selectors] Default namespace gets ignored inside non-type selectors for :is() and :not()
     4        https://bugs.webkit.org/show_bug.cgi?id=219950
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * TestExpectations: Two WPT tests pass now.
     9
    1102020-12-17  Truitt Savell  <tsavell@apple.com>
    211
  • trunk/LayoutTests/TestExpectations

    r270933 r270955  
    12341234webkit.org/b/185859 imported/w3c/web-platform-tests/css/selectors/focus-visible-002.html [ Skip ]
    12351235webkit.org/b/185859 imported/w3c/web-platform-tests/css/selectors/focus-visible-012.html [ Skip ]
    1236 webkit.org/b/219950 imported/w3c/web-platform-tests/css/selectors/is-default-ns-002.html [ ImageOnlyFailure ]
    12371236webkit.org/b/217904 imported/w3c/web-platform-tests/css/selectors/is-where-visited.html [ ImageOnlyFailure ]
    1238 webkit.org/b/219950 imported/w3c/web-platform-tests/css/selectors/not-default-ns-002.html [ ImageOnlyFailure ]
    12391237webkit.org/b/64861 imported/w3c/web-platform-tests/css/selectors/selectors-dir-selector-change-001.html [ ImageOnlyFailure ]
    12401238webkit.org/b/64861 imported/w3c/web-platform-tests/css/selectors/selectors-dir-selector-change-002.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r270952 r270955  
     12020-12-17  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [selectors] Default namespace gets ignored inside non-type selectors for :is() and :not()
     4        https://bugs.webkit.org/show_bug.cgi?id=219950
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Based on Blink r820500 and r820557 by <andruud@chromium.org>.
     9
     10        Default namespace declarations do not affect the compound selector
     11        representing the subject of any selector within a :is() or :not() pseudo-class,
     12        unless that compound selector contains an explicit universal selector or type selector.
     13        Spec: https://drafts.csswg.org/selectors-4/#matches
     14
     15        This patch aligns WebKit implementation with Chromium and Firefox, so two WPT tests pass now.
     16
     17        * css/parser/CSSSelectorParser.cpp:
     18        (WebCore::atEndIgnoringWhitespace):
     19        (WebCore::CSSSelectorParser::consumeCompoundSelector):
     20        (WebCore::CSSSelectorParser::consumePseudo):
     21        (WebCore::CSSSelectorParser::defaultNamespace const):
     22        * css/parser/CSSSelectorParser.h:
     23
    1242020-12-17  Eric Carlson  <eric.carlson@apple.com>
    225
  • trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp

    r268741 r270955  
    3333#include <memory>
    3434#include <wtf/OptionSet.h>
     35#include <wtf/SetForScope.h>
    3536#include <wtf/text/StringBuilder.h>
    3637
     
    325326}
    326327
     328static bool atEndIgnoringWhitespace(CSSParserTokenRange range)
     329{
     330    range.consumeWhitespace();
     331    return range.atEnd();
     332}
     333
    327334std::unique_ptr<CSSParserSelector> CSSSelectorParser::consumeCompoundSelector(CSSParserTokenRange& range)
    328335{
     
    332339    AtomString elementName;
    333340    CSSSelector::PseudoElementType compoundPseudoElement = CSSSelector::PseudoElementUnknown;
    334     if (!consumeName(range, elementName, namespacePrefix)) {
     341    const bool hasName = consumeName(range, elementName, namespacePrefix);
     342    if (!hasName) {
    335343        compoundSelector = consumeSimpleSelector(range);
    336344        if (!compoundSelector)
     
    357365    }
    358366
     367
     368    // While inside a nested selector like :is(), the default namespace shall be ignored when [1]:
     369    // * The compound selector represents the subject [2], and
     370    // * The compound selector does not contain a type/universal selector.
     371    //
     372    // [1] https://drafts.csswg.org/selectors/#matches
     373    // [2] https://drafts.csswg.org/selectors/#selector-subject
     374    SetForScope<bool> ignoreDefaultNamespace(m_ignoreDefaultNamespace, m_resistDefaultNamespace && !hasName && atEndIgnoringWhitespace(range));
    359375    if (!compoundSelector) {
    360376        AtomString namespaceURI = determineNamespace(namespacePrefix);
     
    599615        switch (selector->pseudoClassType()) {
    600616        case CSSSelector::PseudoClassNot: {
     617            SetForScope<bool> resistDefaultNamespace(m_resistDefaultNamespace, true);
    601618            DisallowPseudoElementsScope scope(*this);
    602619            auto selectorList = makeUnique<CSSSelectorList>();
     
    647664        case CSSSelector::PseudoClassMatches:
    648665        case CSSSelector::PseudoClassWhere: {
     666            SetForScope<bool> resistDefaultNamespace(m_resistDefaultNamespace, true);
    649667            DisallowPseudoElementsScope scope(*this);
    650668            auto selectorList = makeUnique<CSSSelectorList>();
     
    898916const AtomString& CSSSelectorParser::defaultNamespace() const
    899917{
    900     if (!m_styleSheet)
     918    if (!m_styleSheet || m_ignoreDefaultNamespace)
    901919        return starAtom();
    902920    return m_styleSheet->defaultNamespace();
  • trunk/Source/WebCore/css/parser/CSSSelectorParser.h

    r268741 r270955  
    8686    bool m_failedParsing { false };
    8787    bool m_disallowPseudoElements { false };
     88    bool m_resistDefaultNamespace { false };
     89    bool m_ignoreDefaultNamespace { false };
    8890};
    8991
Note: See TracChangeset for help on using the changeset viewer.