Skip to content
Permalink
Browse files
[CSS Cascade Layers] CSSImportRule.cssText doesn't include layer para…
…meter

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.



Canonical link: https://commits.webkit.org/244976@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@286668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
anttijk committed Dec 8, 2021
1 parent 4df46b7 commit 006c936c142eed5bb375c4ab4061f3bb5d509bb1
Showing 7 changed files with 77 additions and 18 deletions.
@@ -1,3 +1,12 @@
2021-12-08 Antti Koivisto <antti@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 <antti@apple.com>

[CSS Cascade Layers] Update CSSOM to the spec
@@ -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

@@ -1,3 +1,32 @@
2021-12-08 Antti Koivisto <antti@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 <antti@apple.com>

[CSS Cascade Layers] Update CSSOM to the spec
@@ -32,5 +32,5 @@ typedef USVString CSSOMString;
[
Exposed=Window
] partial interface CSSImportRule {
readonly attribute CSSOMString? layerName;
readonly attribute CSSOMString? layerName;
};
@@ -68,11 +68,25 @@ String CSSImportRule::layerName() const

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
@@ -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 @@ String stringFromCascadeLayerName(const CascadeLayerName& name)
{
StringBuilder result;
for (auto& segment : name) {
result.append(segment);
serializeIdentifier(segment, result);
if (&segment != &name.last())
result.append('.');
}
@@ -565,8 +565,14 @@ RefPtr<StyleRuleImport> CSSParserImpl::consumeImportRule(CSSParserTokenRange pre

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();

0 comments on commit 006c936

Please sign in to comment.