Skip to content

Commit cdbf4f4

Browse files
Calme1709tcl3
authored andcommitted
LibWeb: Support '<zero>' in '<color-stop-angle>`
`<color-stop-angle> = [ <angle-percentage> | <zero> ]{1,2}` but we were previously parsing instead as `<angle-percentage>{1,2}`.
1 parent cc2c8e8 commit cdbf4f4

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Libraries/LibWeb/CSS/Parser/GradientParsing.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,18 @@ Optional<Vector<AngularColorStopListElement>> Parser::parse_angular_color_stop_l
126126
// <angular-color-stop> , [ <angular-color-hint>? , <angular-color-stop> ]#
127127
return parse_color_stop_list<AngularColorStopListElement>(
128128
tokens,
129-
[&](auto& it) { return parse_angle_percentage(it); });
129+
[&](TokenStream<ComponentValue>& it) -> Optional<AnglePercentage> {
130+
if (tokens.next_token().is(Token::Type::Number)) {
131+
auto transaction = tokens.begin_transaction();
132+
auto numeric_value = tokens.consume_a_token().token().number_value();
133+
if (numeric_value == 0) {
134+
transaction.commit();
135+
return Angle::make_degrees(0);
136+
}
137+
}
138+
139+
return parse_angle_percentage(it);
140+
});
130141
}
131142

132143
Optional<InterpolationMethod> Parser::parse_interpolation_method(TokenStream<ComponentValue>& tokens)

Tests/LibWeb/Text/expected/wpt-import/css/css-images/gradient/color-stops-parsing.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ Harness status: OK
22

33
Found 162 tests
44

5-
160 Pass
6-
2 Fail
5+
162 Pass
76
Pass linear-gradient() [ unparsable ]
87
Pass linear-gradient(black, 25%) [ unparsable ]
98
Pass linear-gradient(black, invalid) [ unparsable ]
@@ -125,7 +124,7 @@ Pass conic-gradient(0%, black, white) [ unparsable ]
125124
Pass conic-gradient(black) [ parsable ]
126125
Pass conic-gradient(black 0%) [ parsable ]
127126
Pass conic-gradient(black, white) [ parsable ]
128-
Fail conic-gradient(black 0, white) [ parsable ]
127+
Pass conic-gradient(black 0, white) [ parsable ]
129128
Pass conic-gradient(black 0%, white) [ parsable ]
130129
Pass conic-gradient(black 0%, white 100%) [ parsable ]
131130
Pass conic-gradient(black, green, white) [ parsable ]
@@ -152,7 +151,7 @@ Pass repeating-conic-gradient(0%, black, white) [ unparsable ]
152151
Pass repeating-conic-gradient(black) [ parsable ]
153152
Pass repeating-conic-gradient(black 0%) [ parsable ]
154153
Pass repeating-conic-gradient(black, white) [ parsable ]
155-
Fail repeating-conic-gradient(black 0, white) [ parsable ]
154+
Pass repeating-conic-gradient(black 0, white) [ parsable ]
156155
Pass repeating-conic-gradient(black 0%, white) [ parsable ]
157156
Pass repeating-conic-gradient(black 0%, white 100%) [ parsable ]
158157
Pass repeating-conic-gradient(black, green, white) [ parsable ]

0 commit comments

Comments
 (0)