1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00

LibWeb/CSS: Allow empty trailing group when parsing comma-separated list

There's discussion in the linked spec issue, but the short version is,
this algorithm will see "foo,bar," as a list of two groups, with "foo"
in the first group and "bar" in the second. However, users of this want
to get a list of three groups, with the last one being empty. So, do
that!
This commit is contained in:
Sam Atkins 2025-05-16 20:30:36 +01:00 committed by Tim Ledbetter
parent 338282f74d
commit 233022c473
Notes: github-actions[bot] 2025-05-17 06:54:29 +00:00
3 changed files with 13 additions and 8 deletions

View file

@ -1309,15 +1309,21 @@ Vector<Vector<ComponentValue>> Parser::parse_a_comma_separated_list_of_component
Vector<Vector<ComponentValue>> groups;
// 3. While input is not empty:
bool just_consumed_comma = false;
while (!input.is_empty()) {
// 1. Consume a list of component values from input, with <comma-token> as the stop token, and append the result to groups.
groups.append(consume_a_list_of_component_values(input, Token::Type::Comma));
// 2. Discard a token from input.
input.discard_a_token();
just_consumed_comma = input.consume_a_token().is(Token::Type::Comma);
}
// AD-HOC: Also append an empty group if there was a trailing comma.
// Some related spec discussion: https://github.com/w3c/csswg-drafts/issues/11254
if (just_consumed_comma)
groups.append({});
// 4. Return groups.
return groups;
}

View file

@ -2,8 +2,7 @@ Harness status: OK
Found 18 tests
17 Pass
1 Fail
18 Pass
Pass e.style['font-variation-settings'] = "700" should not set the property value
Pass e.style['font-variation-settings'] = "\"XHGT\"" should not set the property value
Pass e.style['font-variation-settings'] = "wght 700" should not set the property value
@ -16,7 +15,7 @@ Pass e.style['font-variation-settings'] = "\"abcA9\" 0.5" should not set the pro
Pass e.style['font-variation-settings'] = "'wght' 200 'abcd' 400" should not set the property value
Pass e.style['font-variation-settings'] = "'a' 1234" should not set the property value
Pass e.style['font-variation-settings'] = "'abcde' 1234" should not set the property value
Fail e.style['font-variation-settings'] = "'wght' 200, " should not set the property value
Pass e.style['font-variation-settings'] = "'wght' 200, " should not set the property value
Pass e.style['font-variation-settings'] = "'abcd\" 123" should not set the property value
Pass e.style['font-variation-settings'] = "'wght' 100px" should not set the property value
Pass e.style['font-variation-settings'] = "'wght' calc(100px + 200px)" should not set the property value

View file

@ -2,8 +2,8 @@ Harness status: OK
Found 34 tests
30 Pass
4 Fail
32 Pass
2 Fail
Pass Test parsing '' with matchMedia
Pass Test parsing ' ' with matchMedia
Pass Test parsing 'all' with matchMedia
@ -20,9 +20,9 @@ Pass Test parsing 'color)' with matchMedia
Pass Test parsing ' color)' with matchMedia
Pass Test parsing ' color ), ( color' with matchMedia
Fail Test parsing ' foo ' with matchMedia
Fail Test parsing ',' with matchMedia
Pass Test parsing ',' with matchMedia
Pass Test parsing ' , ' with matchMedia
Fail Test parsing ',,' with matchMedia
Pass Test parsing ',,' with matchMedia
Pass Test parsing ' , , ' with matchMedia
Fail Test parsing ' foo,' with matchMedia
Pass Test parsing '(min-resolution: 1x)' with matchMedia