Title: [270955] trunk
Revision
270955
Author
[email protected]
Date
2020-12-17 15:21:58 -0800 (Thu, 17 Dec 2020)

Log 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 <[email protected]>.

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:

* TestExpectations: Two WPT tests pass now.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (270954 => 270955)


--- trunk/LayoutTests/ChangeLog	2020-12-17 23:19:51 UTC (rev 270954)
+++ trunk/LayoutTests/ChangeLog	2020-12-17 23:21:58 UTC (rev 270955)
@@ -1,3 +1,12 @@
+2020-12-17  Manuel Rego Casasnovas  <[email protected]>
+
+        [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.
+
+        * TestExpectations: Two WPT tests pass now.
+
 2020-12-17  Truitt Savell  <[email protected]>
 
         Rebase http/tests/navigation/_javascript_link-frames.html for Big Sur

Modified: trunk/LayoutTests/TestExpectations (270954 => 270955)


--- trunk/LayoutTests/TestExpectations	2020-12-17 23:19:51 UTC (rev 270954)
+++ trunk/LayoutTests/TestExpectations	2020-12-17 23:21:58 UTC (rev 270955)
@@ -1233,9 +1233,7 @@
 imported/w3c/web-platform-tests/css/selectors/old-tests/css3-modsel-173b.xml [ ImageOnlyFailure ]
 webkit.org/b/185859 imported/w3c/web-platform-tests/css/selectors/focus-visible-002.html [ Skip ]
 webkit.org/b/185859 imported/w3c/web-platform-tests/css/selectors/focus-visible-012.html [ Skip ]
-webkit.org/b/219950 imported/w3c/web-platform-tests/css/selectors/is-default-ns-002.html [ ImageOnlyFailure ]
 webkit.org/b/217904 imported/w3c/web-platform-tests/css/selectors/is-where-visited.html [ ImageOnlyFailure ]
-webkit.org/b/219950 imported/w3c/web-platform-tests/css/selectors/not-default-ns-002.html [ ImageOnlyFailure ]
 webkit.org/b/64861 imported/w3c/web-platform-tests/css/selectors/selectors-dir-selector-change-001.html [ ImageOnlyFailure ]
 webkit.org/b/64861 imported/w3c/web-platform-tests/css/selectors/selectors-dir-selector-change-002.html [ ImageOnlyFailure ]
 webkit.org/b/64861 imported/w3c/web-platform-tests/css/selectors/selectors-dir-selector-change-003.html [ ImageOnlyFailure ]

Modified: trunk/Source/WebCore/ChangeLog (270954 => 270955)


--- trunk/Source/WebCore/ChangeLog	2020-12-17 23:19:51 UTC (rev 270954)
+++ trunk/Source/WebCore/ChangeLog	2020-12-17 23:21:58 UTC (rev 270955)
@@ -1,3 +1,26 @@
+2020-12-17  Manuel Rego Casasnovas  <[email protected]>
+
+        [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.
+
+        Based on Blink r820500 and r820557 by <[email protected]>.
+
+        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:
+
 2020-12-17  Eric Carlson  <[email protected]>
 
         [Cocoa] WebM format reader doesn't work with a url in a <source> element

Modified: trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp (270954 => 270955)


--- trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp	2020-12-17 23:19:51 UTC (rev 270954)
+++ trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp	2020-12-17 23:21:58 UTC (rev 270955)
@@ -32,6 +32,7 @@
 
 #include <memory>
 #include <wtf/OptionSet.h>
+#include <wtf/SetForScope.h>
 #include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
@@ -324,6 +325,12 @@
     return isPseudoClassValidAfterPseudoElement(pseudo, compoundPseudoElement);
 }
 
+static bool atEndIgnoringWhitespace(CSSParserTokenRange range)
+{
+    range.consumeWhitespace();
+    return range.atEnd();
+}
+
 std::unique_ptr<CSSParserSelector> CSSSelectorParser::consumeCompoundSelector(CSSParserTokenRange& range)
 {
     std::unique_ptr<CSSParserSelector> compoundSelector;
@@ -331,7 +338,8 @@
     AtomString namespacePrefix;
     AtomString elementName;
     CSSSelector::PseudoElementType compoundPseudoElement = CSSSelector::PseudoElementUnknown;
-    if (!consumeName(range, elementName, namespacePrefix)) {
+    const bool hasName = consumeName(range, elementName, namespacePrefix);
+    if (!hasName) {
         compoundSelector = consumeSimpleSelector(range);
         if (!compoundSelector)
             return nullptr;
@@ -356,6 +364,14 @@
             compoundSelector = WTFMove(simpleSelector);
     }
 
+
+    // While inside a nested selector like :is(), the default namespace shall be ignored when [1]:
+    // * The compound selector represents the subject [2], and
+    // * The compound selector does not contain a type/universal selector.
+    //
+    // [1] https://drafts.csswg.org/selectors/#matches
+    // [2] https://drafts.csswg.org/selectors/#selector-subject
+    SetForScope<bool> ignoreDefaultNamespace(m_ignoreDefaultNamespace, m_resistDefaultNamespace && !hasName && atEndIgnoringWhitespace(range));
     if (!compoundSelector) {
         AtomString namespaceURI = determineNamespace(namespacePrefix);
         if (namespaceURI.isNull()) {
@@ -598,6 +614,7 @@
     if (selector->match() == CSSSelector::PseudoClass) {
         switch (selector->pseudoClassType()) {
         case CSSSelector::PseudoClassNot: {
+            SetForScope<bool> resistDefaultNamespace(m_resistDefaultNamespace, true);
             DisallowPseudoElementsScope scope(*this);
             auto selectorList = makeUnique<CSSSelectorList>();
             *selectorList = consumeComplexSelectorList(block);
@@ -646,6 +663,7 @@
         case CSSSelector::PseudoClassIs:
         case CSSSelector::PseudoClassMatches:
         case CSSSelector::PseudoClassWhere: {
+            SetForScope<bool> resistDefaultNamespace(m_resistDefaultNamespace, true);
             DisallowPseudoElementsScope scope(*this);
             auto selectorList = makeUnique<CSSSelectorList>();
             *selectorList = consumeComplexForgivingSelectorList(block);
@@ -897,7 +915,7 @@
 
 const AtomString& CSSSelectorParser::defaultNamespace() const
 {
-    if (!m_styleSheet)
+    if (!m_styleSheet || m_ignoreDefaultNamespace)
         return starAtom();
     return m_styleSheet->defaultNamespace();
 }

Modified: trunk/Source/WebCore/css/parser/CSSSelectorParser.h (270954 => 270955)


--- trunk/Source/WebCore/css/parser/CSSSelectorParser.h	2020-12-17 23:19:51 UTC (rev 270954)
+++ trunk/Source/WebCore/css/parser/CSSSelectorParser.h	2020-12-17 23:21:58 UTC (rev 270955)
@@ -85,6 +85,8 @@
     const RefPtr<StyleSheetContents> m_styleSheet;
     bool m_failedParsing { false };
     bool m_disallowPseudoElements { false };
+    bool m_resistDefaultNamespace { false };
+    bool m_ignoreDefaultNamespace { false };
 };
 
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to