Changeset 286668 in webkit


Ignore:
Timestamp:
Dec 8, 2021 11:16:05 AM (7 months ago)
Author:
Antti Koivisto
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.

Location:
trunk
Files:
7 edited

Legend:

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

    r286657 r286668  
     12021-12-08  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS Cascade Layers] CSSImportRule.cssText doesn't include layer parameter
     4        https://bugs.webkit.org/show_bug.cgi?id=234010
     5
     6        Reviewed by Simon Fraser.
     7
     8        * web-platform-tests/css/css-cascade/parsing/layer-import-parsing-expected.txt:
     9
    1102021-12-08  Antti Koivisto  <antti@apple.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-cascade/parsing/layer-import-parsing-expected.txt

    r286647 r286668  
    11
    2 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\");"
    3 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\");"
    4 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\");"
    5 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\");"
    6 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\");"
    7 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\");"
    8 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\");"
    9 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\");"
    10 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\");"
    11 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
    12 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
    13 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
    14 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
     2PASS @import url("nonexist.css") layer; should be a valid layered import rule
     3PASS @import url("nonexist.css") layer(A); should be a valid layered import rule
     4PASS @import url("nonexist.css") layer(A.B); should be a valid layered import rule
     5PASS @import url(nonexist.css) layer; should be a valid layered import rule
     6PASS @import url(nonexist.css) layer(A); should be a valid layered import rule
     7PASS @import url(nonexist.css) layer(A.B); should be a valid layered import rule
     8PASS @import "nonexist.css" layer; should be a valid layered import rule
     9PASS @import "nonexist.css" layer(A); should be a valid layered import rule
     10PASS @import "nonexist.css" layer(A.B); should be a valid layered import rule
     11PASS @import url("nonexist.css") layer(); should still be a valid import rule with an invalid layer declaration
     12PASS @import url("nonexist.css") layer(A B); should still be a valid import rule with an invalid layer declaration
     13PASS @import url("nonexist.css") layer(A . B); should still be a valid import rule with an invalid layer declaration
     14PASS @import url("nonexist.css") layer(A, B, C); should still be a valid import rule with an invalid layer declaration
    1515
  • trunk/Source/WebCore/ChangeLog

    r286657 r286668  
     12021-12-08  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS Cascade Layers] CSSImportRule.cssText doesn't include layer parameter
     4        https://bugs.webkit.org/show_bug.cgi?id=234010
     5
     6        Reviewed by Simon Fraser.
     7
     8        Fix serialization of import rules than include layer, like
     9
     10        @import url(foo.css) layer(A);
     11
     12        Also make the parsing of the layer() argument stricter.
     13
     14        * css/CSSImportRule.cpp:
     15        (WebCore::CSSImportRule::cssText const):
     16
     17        Serialize the layer.
     18
     19        * css/CSSLayerBlockRule.cpp:
     20        (WebCore::stringFromCascadeLayerName):
     21
     22        Serialize layer name segments as identifiers.
     23
     24        * css/parser/CSSParserImpl.cpp:
     25        (WebCore::CSSParserImpl::consumeImportRule):
     26
     27        Fail parsing if there is anything left in the function argument after consuming the layer name.
     28        If the parsing fails, revert and try the full string as media query.
     29
    1302021-12-08  Antti Koivisto  <antti@apple.com>
    231
  • trunk/Source/WebCore/css/CSSImportRule+Layer.idl

    r286657 r286668  
    3333    Exposed=Window
    3434] partial interface CSSImportRule {
    35   readonly attribute CSSOMString? layerName;
     35    readonly attribute CSSOMString? layerName;
    3636};
  • trunk/Source/WebCore/css/CSSImportRule.cpp

    r286657 r286668  
    6969String CSSImportRule::cssText() const
    7070{
     71    StringBuilder builder;
     72
     73    builder.append("@import ", serializeURL(m_importRule.get().href()));
     74
     75    if (auto layerName = this->layerName(); !layerName.isNull()) {
     76        if (layerName.isEmpty())
     77            builder.append(" layer");
     78        else
     79            builder.append(" layer(", layerName, ')');
     80    }
     81
    7182    if (auto queries = m_importRule.get().mediaQueries()) {
    7283        if (auto mediaText = queries->mediaText(); !mediaText.isEmpty())
    73             return makeString("@import url(\"", m_importRule.get().href(), "\") ", mediaText, ';');
     84            builder.append(' ', mediaText);
    7485    }
    75     return makeString("@import url(\"", m_importRule.get().href(), "\");");
     86
     87    builder.append(';');
     88
     89    return builder.toString();
    7690}
    7791
  • trunk/Source/WebCore/css/CSSLayerBlockRule.cpp

    r286657 r286668  
    3131#include "CSSLayerBlockRule.h"
    3232
     33#include "CSSMarkup.h"
    3334#include "CSSStyleSheet.h"
    3435#include "StyleRule.h"
     
    7677    StringBuilder result;
    7778    for (auto& segment : name) {
    78         result.append(segment);
     79        serializeIdentifier(segment, result);
    7980        if (&segment != &name.last())
    8081            result.append('.');
  • trunk/Source/WebCore/css/parser/CSSParserImpl.cpp

    r286657 r286668  
    566566        auto& token = prelude.peek();
    567567        if (token.type() == FunctionToken && equalIgnoringASCIICase(token.value(), "layer")) {
     568            auto savedPreludeForFailure = prelude;
    568569            auto contents = CSSPropertyParserHelpers::consumeFunction(prelude);
    569             return consumeCascadeLayerName(contents, AllowAnonymous::No);
     570            auto layerName = consumeCascadeLayerName(contents, AllowAnonymous::No);
     571            if (!layerName || !contents.atEnd()) {
     572                prelude = savedPreludeForFailure;
     573                return { };
     574            }
     575            return layerName;
    570576        }
    571577        if (token.type() == IdentToken && equalIgnoringASCIICase(token.value(), "layer")) {
Note: See TracChangeset for help on using the changeset viewer.