Skip to content

Commit 2f1e72c

Browse files
committed
[@Property] syntax "<color> | <color>+" does not match "yellow blue"
https://bugs.webkit.org/show_bug.cgi?id=250898 <rdar://problem/104475106> Reviewed by Sam Weinig. * LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/register-property-syntax-parsing-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/register-property-syntax-parsing.html: Add more tests for lists and |. * Source/WebCore/css/parser/CSSPropertyParser.cpp: (WebCore::CSSPropertyParser::consumeCustomPropertyValueWithSyntax): Always restore the state and continue when tokens don't match the syntax, or aren't consumed fully. Canonical link: https://commits.webkit.org/259166@main
1 parent b1c7a7d commit 2f1e72c

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/register-property-syntax-parsing-expected.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,32 @@ PASS syntax:'<color>', initialValue:'lightgoldenrodyellow' is valid
5959
PASS syntax:'<image>', initialValue:'url(a)' is valid
6060
PASS syntax:'<image>', initialValue:'linear-gradient(yellow, blue)' is valid
6161
PASS syntax:'<url>', initialValue:'url(a)' is valid
62+
PASS syntax:'<color>+', initialValue:'yellow blue' is valid
63+
PASS syntax:'<color>+ | <color>', initialValue:'yellow blue' is valid
64+
PASS syntax:'<color> | <color>+', initialValue:'yellow blue' is valid
65+
PASS syntax:'<color># | <color>', initialValue:'yellow, blue' is valid
66+
PASS syntax:'<color> | <color>#', initialValue:'yellow, blue' is valid
67+
PASS syntax:'<color># | <color>+', initialValue:'yellow blue' is valid
68+
PASS syntax:'<color>+ | <color>#', initialValue:'yellow, blue' is valid
69+
PASS syntax:'<color>+ | yellow', initialValue:'yellow blue' is valid
70+
PASS syntax:'yellow', initialValue:'yellow' is valid
71+
PASS syntax:'yellow | <color>+', initialValue:'yellow blue' is valid
72+
PASS syntax:'<color># | yellow', initialValue:'yellow, blue' is valid
73+
PASS syntax:'yellow | <color>#', initialValue:'yellow, blue' is valid
74+
PASS syntax:'<transform-list> | <transform-function> ', initialValue:'scale(2) rotate(90deg)' is valid
75+
PASS syntax:'<transform-function> | <transform-list>', initialValue:'scale(2) rotate(90deg)' is valid
76+
PASS syntax:'<transform-list> | <transform-function>+ ', initialValue:'scale(2) rotate(90deg)' is valid
77+
PASS syntax:'<transform-function>+ | <transform-list>', initialValue:'scale(2) rotate(90deg)' is valid
78+
PASS syntax:'<transform-list> | <transform-function># ', initialValue:'scale(2) rotate(90deg)' is valid
79+
PASS syntax:'<transform-function># | <transform-list>', initialValue:'scale(2) rotate(90deg)' is valid
80+
PASS syntax:'<transform-list> | <transform-function># ', initialValue:'scale(2), rotate(90deg)' is valid
81+
PASS syntax:'<transform-function># | <transform-list>', initialValue:'scale(2), rotate(90deg)' is valid
82+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1' is valid
83+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1 1' is valid
84+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1%' is valid
85+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1% 1%' is valid
86+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1px' is valid
87+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1px 1px' is valid
6288
PASS syntax:'banana', initialValue:'banana' is valid
6389
PASS syntax:'bAnAnA', initialValue:'bAnAnA' is valid
6490
PASS syntax:'ba-na-nya', initialValue:'ba-na-nya' is valid
@@ -109,6 +135,12 @@ PASS syntax:'foo § bar', initialValue:'foo § bar' is invalid
109135
PASS syntax:'foo \1F914 bar', initialValue:'foo \1F914 bar' is invalid
110136
PASS syntax:'<length> <number>', initialValue:'0px 0' is invalid
111137
PASS syntax:'<length> <length> <length>', initialValue:'0px 0px 0px' is invalid
138+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1 1%' is invalid
139+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1% 1' is invalid
140+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1px 1' is invalid
141+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1 1px' is invalid
142+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1px 1%' is invalid
143+
PASS syntax:'<integer>+ | <percentage>+ | <length>+ ', initialValue:'1% 1px' is invalid
112144
PASS syntax:'initial', initialValue:'initial' is invalid
113145
PASS syntax:'inherit', initialValue:'inherit' is invalid
114146
PASS syntax:'unset', initialValue:'unset' is invalid

LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/register-property-syntax-parsing.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,33 @@
8888
assert_valid("<image>", "linear-gradient(yellow, blue)");
8989
assert_valid("<url>", "url(a)");
9090

91+
assert_valid("<color>+", "yellow blue");
92+
assert_valid("<color>+ | <color>", "yellow blue");
93+
assert_valid("<color> | <color>+", "yellow blue");
94+
assert_valid("<color># | <color>", "yellow, blue");
95+
assert_valid("<color> | <color>#", "yellow, blue");
96+
assert_valid("<color># | <color>+", "yellow blue");
97+
assert_valid("<color>+ | <color>#", "yellow, blue");
98+
assert_valid("<color>+ | yellow", "yellow blue");
99+
assert_valid("yellow", "yellow");
100+
assert_valid("yellow | <color>+", "yellow blue");
101+
assert_valid("<color># | yellow", "yellow, blue");
102+
assert_valid("yellow | <color>#", "yellow, blue");
103+
assert_valid("<transform-list> | <transform-function> ", "scale(2) rotate(90deg)");
104+
assert_valid("<transform-function> | <transform-list>", "scale(2) rotate(90deg)");
105+
assert_valid("<transform-list> | <transform-function>+ ", "scale(2) rotate(90deg)");
106+
assert_valid("<transform-function>+ | <transform-list>", "scale(2) rotate(90deg)");
107+
assert_valid("<transform-list> | <transform-function># ", "scale(2) rotate(90deg)");
108+
assert_valid("<transform-function># | <transform-list>", "scale(2) rotate(90deg)");
109+
assert_valid("<transform-list> | <transform-function># ", "scale(2), rotate(90deg)");
110+
assert_valid("<transform-function># | <transform-list>", "scale(2), rotate(90deg)");
111+
assert_valid("<integer>+ | <percentage>+ | <length>+ ", "1");
112+
assert_valid("<integer>+ | <percentage>+ | <length>+ ", "1 1");
113+
assert_valid("<integer>+ | <percentage>+ | <length>+ ", "1%");
114+
assert_valid("<integer>+ | <percentage>+ | <length>+ ", "1% 1%");
115+
assert_valid("<integer>+ | <percentage>+ | <length>+ ", "1px");
116+
assert_valid("<integer>+ | <percentage>+ | <length>+ ", "1px 1px");
117+
91118
assert_valid("banana", "banana");
92119
assert_valid("bAnAnA", "bAnAnA");
93120
assert_valid("ba-na-nya", "ba-na-nya");
@@ -142,6 +169,13 @@
142169
assert_invalid("<length> <number>", "0px 0");
143170
assert_invalid("<length> <length> <length>", "0px 0px 0px");
144171

172+
assert_invalid("<integer>+ | <percentage>+ | <length>+ ", "1 1%");
173+
assert_invalid("<integer>+ | <percentage>+ | <length>+ ", "1% 1");
174+
assert_invalid("<integer>+ | <percentage>+ | <length>+ ", "1px 1");
175+
assert_invalid("<integer>+ | <percentage>+ | <length>+ ", "1 1px");
176+
assert_invalid("<integer>+ | <percentage>+ | <length>+ ", "1px 1%");
177+
assert_invalid("<integer>+ | <percentage>+ | <length>+ ", "1% 1px");
178+
145179
assert_invalid("initial", "initial");
146180
assert_invalid("inherit", "inherit");
147181
assert_invalid("unset", "unset");

Source/WebCore/css/parser/CSSPropertyParser.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ std::pair<RefPtr<CSSValue>, CSSCustomPropertySyntax::Type> CSSPropertyParser::co
359359
if (auto value = consumeCustomIdent(range)) {
360360
if (component.ident.isNull() || value->stringValue() == component.ident)
361361
return value;
362-
range = rangeCopy;
363362
}
364363
return nullptr;
365364
case CSSCustomPropertySyntax::Type::Percentage:
@@ -416,10 +415,10 @@ std::pair<RefPtr<CSSValue>, CSSCustomPropertySyntax::Type> CSSPropertyParser::co
416415

417416
for (auto& component : syntax.definition) {
418417
if (auto value = consumeComponent(m_range, component)) {
419-
if (!m_range.atEnd())
420-
break;
421-
return { value, component.type };
418+
if (m_range.atEnd())
419+
return { value, component.type };
422420
}
421+
m_range = rangeCopy;
423422
}
424423
return { nullptr, CSSCustomPropertySyntax::Type::Unknown };
425424
}

0 commit comments

Comments
 (0)