Title: [286668] trunk
Revision
286668
Author
an...@apple.com
Date
2021-12-08 11:16:05 -0800 (Wed, 08 Dec 2021)

Log Message

[CSS Cascade Layers] CSSImportRule.cssText doesn't include layer parameter
https://bugs.webkit.org/show_bug.cgi?id=234010

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

* web-platform-tests/css/css-cascade/parsing/layer-import-parsing-expected.txt:

Source/WebCore:

Fix serialization of import rules than include layer, like

@import url(foo.css) layer(A);

Also make the parsing of the layer() argument stricter.

* css/CSSImportRule.cpp:
(WebCore::CSSImportRule::cssText const):

Serialize the layer.

* css/CSSLayerBlockRule.cpp:
(WebCore::stringFromCascadeLayerName):

Serialize layer name segments as identifiers.

* css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::consumeImportRule):

Fail parsing if there is anything left in the function argument after consuming the layer name.
If the parsing fails, revert and try the full string as media query.

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (286667 => 286668)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-12-08 19:11:40 UTC (rev 286667)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-12-08 19:16:05 UTC (rev 286668)
@@ -1,5 +1,14 @@
 2021-12-08  Antti Koivisto  <an...@apple.com>
 
+        [CSS Cascade Layers] CSSImportRule.cssText doesn't include layer parameter
+        https://bugs.webkit.org/show_bug.cgi?id=234010
+
+        Reviewed by Simon Fraser.
+
+        * web-platform-tests/css/css-cascade/parsing/layer-import-parsing-expected.txt:
+
+2021-12-08  Antti Koivisto  <an...@apple.com>
+
         [CSS Cascade Layers] Update CSSOM to the spec
         https://bugs.webkit.org/show_bug.cgi?id=231340
         <rdar://problem/83958697>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-cascade/parsing/layer-import-parsing-expected.txt (286667 => 286668)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-cascade/parsing/layer-import-parsing-expected.txt	2021-12-08 19:11:40 UTC (rev 286667)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-cascade/parsing/layer-import-parsing-expected.txt	2021-12-08 19:16:05 UTC (rev 286668)
@@ -1,15 +1,15 @@
 
-FAIL @import url("nonexist.css") layer; should be a valid layered import rule assert_equals: serialization should be canonical expected "@import url(\"nonexist.css\") layer;" but got "@import url(\"nonexist.css\");"
-FAIL @import url("nonexist.css") layer(A); should be a valid layered import rule assert_equals: serialization should be canonical expected "@import url(\"nonexist.css\") layer(A);" but got "@import url(\"nonexist.css\");"
-FAIL @import url("nonexist.css") layer(A.B); should be a valid layered import rule assert_equals: serialization should be canonical expected "@import url(\"nonexist.css\") layer(A.B);" but got "@import url(\"nonexist.css\");"
-FAIL @import url(nonexist.css) layer; should be a valid layered import rule assert_equals: serialization should be canonical expected "@import url(\"nonexist.css\") layer;" but got "@import url(\"nonexist.css\");"
-FAIL @import url(nonexist.css) layer(A); should be a valid layered import rule assert_equals: serialization should be canonical expected "@import url(\"nonexist.css\") layer(A);" but got "@import url(\"nonexist.css\");"
-FAIL @import url(nonexist.css) layer(A.B); should be a valid layered import rule assert_equals: serialization should be canonical expected "@import url(\"nonexist.css\") layer(A.B);" but got "@import url(\"nonexist.css\");"
-FAIL @import "nonexist.css" layer; should be a valid layered import rule assert_equals: serialization should be canonical expected "@import url(\"nonexist.css\") layer;" but got "@import url(\"nonexist.css\");"
-FAIL @import "nonexist.css" layer(A); should be a valid layered import rule assert_equals: serialization should be canonical expected "@import url(\"nonexist.css\") layer(A);" but got "@import url(\"nonexist.css\");"
-FAIL @import "nonexist.css" layer(A.B); should be a valid layered import rule assert_equals: serialization should be canonical expected "@import url(\"nonexist.css\") layer(A.B);" but got "@import url(\"nonexist.css\");"
-FAIL @import url("nonexist.css") layer(); should still be a valid import rule with an invalid layer declaration assert_not_equals: invalid layer declaration should be parsed as <general-enclosed> media query got disallowed value 0
-FAIL @import url("nonexist.css") layer(A B); should still be a valid import rule with an invalid layer declaration assert_not_equals: invalid layer declaration should be parsed as <general-enclosed> media query got disallowed value 0
-FAIL @import url("nonexist.css") layer(A . B); should still be a valid import rule with an invalid layer declaration assert_not_equals: invalid layer declaration should be parsed as <general-enclosed> media query got disallowed value 0
-FAIL @import url("nonexist.css") layer(A, B, C); should still be a valid import rule with an invalid layer declaration assert_not_equals: invalid layer declaration should be parsed as <general-enclosed> media query got disallowed value 0
+PASS @import url("nonexist.css") layer; should be a valid layered import rule
+PASS @import url("nonexist.css") layer(A); should be a valid layered import rule
+PASS @import url("nonexist.css") layer(A.B); should be a valid layered import rule
+PASS @import url(nonexist.css) layer; should be a valid layered import rule
+PASS @import url(nonexist.css) layer(A); should be a valid layered import rule
+PASS @import url(nonexist.css) layer(A.B); should be a valid layered import rule
+PASS @import "nonexist.css" layer; should be a valid layered import rule
+PASS @import "nonexist.css" layer(A); should be a valid layered import rule
+PASS @import "nonexist.css" layer(A.B); should be a valid layered import rule
+PASS @import url("nonexist.css") layer(); should still be a valid import rule with an invalid layer declaration
+PASS @import url("nonexist.css") layer(A B); should still be a valid import rule with an invalid layer declaration
+PASS @import url("nonexist.css") layer(A . B); should still be a valid import rule with an invalid layer declaration
+PASS @import url("nonexist.css") layer(A, B, C); should still be a valid import rule with an invalid layer declaration
 

Modified: trunk/Source/WebCore/ChangeLog (286667 => 286668)


--- trunk/Source/WebCore/ChangeLog	2021-12-08 19:11:40 UTC (rev 286667)
+++ trunk/Source/WebCore/ChangeLog	2021-12-08 19:16:05 UTC (rev 286668)
@@ -1,5 +1,34 @@
 2021-12-08  Antti Koivisto  <an...@apple.com>
 
+        [CSS Cascade Layers] CSSImportRule.cssText doesn't include layer parameter
+        https://bugs.webkit.org/show_bug.cgi?id=234010
+
+        Reviewed by Simon Fraser.
+
+        Fix serialization of import rules than include layer, like
+
+        @import url(foo.css) layer(A);
+
+        Also make the parsing of the layer() argument stricter.
+
+        * css/CSSImportRule.cpp:
+        (WebCore::CSSImportRule::cssText const):
+
+        Serialize the layer.
+
+        * css/CSSLayerBlockRule.cpp:
+        (WebCore::stringFromCascadeLayerName):
+
+        Serialize layer name segments as identifiers.
+
+        * css/parser/CSSParserImpl.cpp:
+        (WebCore::CSSParserImpl::consumeImportRule):
+
+        Fail parsing if there is anything left in the function argument after consuming the layer name.
+        If the parsing fails, revert and try the full string as media query.
+
+2021-12-08  Antti Koivisto  <an...@apple.com>
+
         [CSS Cascade Layers] Update CSSOM to the spec
         https://bugs.webkit.org/show_bug.cgi?id=231340
         <rdar://problem/83958697>

Modified: trunk/Source/WebCore/css/CSSImportRule+Layer.idl (286667 => 286668)


--- trunk/Source/WebCore/css/CSSImportRule+Layer.idl	2021-12-08 19:11:40 UTC (rev 286667)
+++ trunk/Source/WebCore/css/CSSImportRule+Layer.idl	2021-12-08 19:16:05 UTC (rev 286668)
@@ -32,5 +32,5 @@
 [
     Exposed=Window
 ] partial interface CSSImportRule {
-  readonly attribute CSSOMString? layerName;
+    readonly attribute CSSOMString? layerName;
 };

Modified: trunk/Source/WebCore/css/CSSImportRule.cpp (286667 => 286668)


--- trunk/Source/WebCore/css/CSSImportRule.cpp	2021-12-08 19:11:40 UTC (rev 286667)
+++ trunk/Source/WebCore/css/CSSImportRule.cpp	2021-12-08 19:16:05 UTC (rev 286668)
@@ -68,11 +68,25 @@
 
 String CSSImportRule::cssText() const
 {
+    StringBuilder builder;
+
+    builder.append("@import ", serializeURL(m_importRule.get().href()));
+
+    if (auto layerName = this->layerName(); !layerName.isNull()) {
+        if (layerName.isEmpty())
+            builder.append(" layer");
+        else
+            builder.append(" layer(", layerName, ')');
+    }
+
     if (auto queries = m_importRule.get().mediaQueries()) {
         if (auto mediaText = queries->mediaText(); !mediaText.isEmpty())
-            return makeString("@import url(\"", m_importRule.get().href(), "\") ", mediaText, ';');
+            builder.append(' ', mediaText);
     }
-    return makeString("@import url(\"", m_importRule.get().href(), "\");");
+
+    builder.append(';');
+
+    return builder.toString();
 }
 
 CSSStyleSheet* CSSImportRule::styleSheet() const

Modified: trunk/Source/WebCore/css/CSSLayerBlockRule.cpp (286667 => 286668)


--- trunk/Source/WebCore/css/CSSLayerBlockRule.cpp	2021-12-08 19:11:40 UTC (rev 286667)
+++ trunk/Source/WebCore/css/CSSLayerBlockRule.cpp	2021-12-08 19:16:05 UTC (rev 286668)
@@ -30,6 +30,7 @@
 #include "config.h"
 #include "CSSLayerBlockRule.h"
 
+#include "CSSMarkup.h"
 #include "CSSStyleSheet.h"
 #include "StyleRule.h"
 #include <wtf/text/StringBuilder.h>
@@ -75,7 +76,7 @@
 {
     StringBuilder result;
     for (auto& segment : name) {
-        result.append(segment);
+        serializeIdentifier(segment, result);
         if (&segment != &name.last())
             result.append('.');
     }

Modified: trunk/Source/WebCore/css/parser/CSSParserImpl.cpp (286667 => 286668)


--- trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2021-12-08 19:11:40 UTC (rev 286667)
+++ trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2021-12-08 19:16:05 UTC (rev 286668)
@@ -565,8 +565,14 @@
 
         auto& token = prelude.peek();
         if (token.type() == FunctionToken && equalIgnoringASCIICase(token.value(), "layer")) {
+            auto savedPreludeForFailure = prelude;
             auto contents = CSSPropertyParserHelpers::consumeFunction(prelude);
-            return consumeCascadeLayerName(contents, AllowAnonymous::No);
+            auto layerName = consumeCascadeLayerName(contents, AllowAnonymous::No);
+            if (!layerName || !contents.atEnd()) {
+                prelude = savedPreludeForFailure;
+                return { };
+            }
+            return layerName;
         }
         if (token.type() == IdentToken && equalIgnoringASCIICase(token.value(), "layer")) {
             prelude.consumeIncludingWhitespace();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to