LibWeb/CSS: Reject invalid grid track placement property values

This commit is contained in:
Tim Ledbetter 2025-03-11 11:16:02 +00:00 committed by Jelle Raaijmakers
parent 411cafa2a9
commit b80c0d2114
Notes: github-actions[bot] 2025-03-14 07:51:00 +00:00
5 changed files with 79 additions and 75 deletions

View file

@ -3980,8 +3980,11 @@ RefPtr<CSSStyleValue> Parser::parse_grid_track_placement_shorthand_value(Propert
Vector<ComponentValue> track_start_placement_tokens;
while (true) {
if (current_token->is_delim('/'))
if (current_token->is_delim('/')) {
if (!tokens.has_next_token())
return nullptr;
break;
}
track_start_placement_tokens.append(current_token);
if (!tokens.has_next_token())
break;

View file

@ -3127,6 +3127,9 @@ RefPtr<GridTrackPlacementStyleValue> Parser::parse_grid_track_placement(TokenStr
if (!tokens.has_next_token())
return nullptr;
if (tokens.remaining_token_count() > 3)
return nullptr;
// https://www.w3.org/TR/css-grid-2/#line-placement
// Line-based Placement: the grid-row-start, grid-column-start, grid-row-end, and grid-column-end properties
// <grid-line> =
@ -3169,10 +3172,6 @@ RefPtr<GridTrackPlacementStyleValue> Parser::parse_grid_track_placement(TokenStr
transaction.commit();
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_auto());
}
if (token.is_ident("span"sv)) {
transaction.commit();
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_span(1));
}
if (is_valid_integer(token)) {
transaction.commit();
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_line(static_cast<int>(token.token().number_value()), {}));
@ -3191,6 +3190,8 @@ RefPtr<GridTrackPlacementStyleValue> Parser::parse_grid_track_placement(TokenStr
if (span_value)
return nullptr;
tokens.discard_a_token(); // span
if (tokens.has_next_token() && ((span_or_position_value != 0 && identifier_value.is_empty()) || (span_or_position_value == 0 && !identifier_value.is_empty())))
return nullptr;
span_value = true;
continue;
}
@ -3209,6 +3210,9 @@ RefPtr<GridTrackPlacementStyleValue> Parser::parse_grid_track_placement(TokenStr
break;
}
if (tokens.has_next_token())
return nullptr;
// Negative integers or zero are invalid.
if (span_value && span_or_position_value < 1)
return nullptr;

View file

@ -2,15 +2,14 @@ Harness status: OK
Found 25 tests
21 Pass
4 Fail
25 Pass
Pass e.style['grid-area'] = "'string'" should not set the property value
Pass e.style['grid-row'] = "1.0" should not set the property value
Pass e.style['grid-column'] = "1 2" should not set the property value
Pass e.style['grid-row-start'] = "+-3" should not set the property value
Pass e.style['grid-column-start'] = "0" should not set the property value
Fail e.style['grid-row-end'] = "span" should not set the property value
Fail e.style['grid-column-end'] = "sPaN" should not set the property value
Pass e.style['grid-row-end'] = "span" should not set the property value
Pass e.style['grid-column-end'] = "sPaN" should not set the property value
Pass e.style['grid-column-end'] = "\"1st\"" should not set the property value
Pass e.style['grid-column-end'] = "1st" should not set the property value
Pass e.style['grid-column-start'] = "auto 1" should not set the property value
@ -19,8 +18,8 @@ Pass e.style['grid-area'] = "auto / initial" should not set the property value
Pass e.style['grid-row'] = "auto / inherit" should not set the property value
Pass e.style['grid-column'] = "auto / unset" should not set the property value
Pass e.style['grid-area'] = "auto / auto / auto / auto / auto" should not set the property value
Fail e.style['grid-row'] = "1 / 2 / 3" should not set the property value
Fail e.style['grid-column'] = "a / b / c" should not set the property value
Pass e.style['grid-row'] = "1 / 2 / 3" should not set the property value
Pass e.style['grid-column'] = "a / b / c" should not set the property value
Pass e.style['grid-row-end'] = "span 1 / span 2" should not set the property value
Pass e.style['grid-area'] = "auto 2 auto 4" should not set the property value
Pass e.style['grid-row'] = "33 -A0 auto" should not set the property value

View file

@ -2,36 +2,35 @@ Harness status: OK
Found 31 tests
1 Pass
30 Fail
31 Pass
Pass e.style['grid-column'] = "4 5" should not set the property value
Fail e.style['grid-column'] = "4 /" should not set the property value
Fail e.style['grid-column'] = "5 5" should not set the property value
Fail e.style['grid-column'] = "5 / /" should not set the property value
Fail e.style['grid-column'] = "0 / 5" should not set the property value
Fail e.style['grid-column'] = "6 / 0" should not set the property value
Fail e.style['grid-column'] = "0" should not set the property value
Fail e.style['grid-column'] = "span" should not set the property value
Fail e.style['grid-column'] = "span / span" should not set the property value
Fail e.style['grid-column'] = "span span / span span" should not set the property value
Fail e.style['grid-column'] = "5 5 / span 2" should not set the property value
Fail e.style['grid-column'] = "5 first last / span 2" should not set the property value
Fail e.style['grid-column'] = "5 / first last 2" should not set the property value
Fail e.style['grid-column'] = "first last / span 2" should not set the property value
Fail e.style['grid-column'] = "5 / first last" should not set the property value
Fail e.style['grid-column'] = "5 5 span / 2" should not set the property value
Fail e.style['grid-column'] = "span 3 5 / 1" should not set the property value
Fail e.style['grid-column'] = "span last first / 1" should not set the property value
Fail e.style['grid-column'] = "2 / span last first" should not set the property value
Fail e.style['grid-column'] = "span 1 last first / 1" should not set the property value
Fail e.style['grid-column'] = "2 / span last 3 first" should not set the property value
Fail e.style['grid-column'] = "1 span 2 first / 1" should not set the property value
Fail e.style['grid-column'] = "2 / 3 span 3 first" should not set the property value
Fail e.style['grid-column'] = "span -1 / -2" should not set the property value
Fail e.style['grid-column'] = "-1 / -2 span" should not set the property value
Fail e.style['grid-column'] = "0 span / 0" should not set the property value
Fail e.style['grid-column'] = "0 / span 0" should not set the property value
Fail e.style['grid-column'] = "span -3 'first' / 3 last" should not set the property value
Fail e.style['grid-column'] = "first span 1 / last" should not set the property value
Fail e.style['grid-column'] = "3 first / 2 span last" should not set the property value
Fail e.style['grid-column'] = "3 / 1 span 2" should not set the property value
Pass e.style['grid-column'] = "4 /" should not set the property value
Pass e.style['grid-column'] = "5 5" should not set the property value
Pass e.style['grid-column'] = "5 / /" should not set the property value
Pass e.style['grid-column'] = "0 / 5" should not set the property value
Pass e.style['grid-column'] = "6 / 0" should not set the property value
Pass e.style['grid-column'] = "0" should not set the property value
Pass e.style['grid-column'] = "span" should not set the property value
Pass e.style['grid-column'] = "span / span" should not set the property value
Pass e.style['grid-column'] = "span span / span span" should not set the property value
Pass e.style['grid-column'] = "5 5 / span 2" should not set the property value
Pass e.style['grid-column'] = "5 first last / span 2" should not set the property value
Pass e.style['grid-column'] = "5 / first last 2" should not set the property value
Pass e.style['grid-column'] = "first last / span 2" should not set the property value
Pass e.style['grid-column'] = "5 / first last" should not set the property value
Pass e.style['grid-column'] = "5 5 span / 2" should not set the property value
Pass e.style['grid-column'] = "span 3 5 / 1" should not set the property value
Pass e.style['grid-column'] = "span last first / 1" should not set the property value
Pass e.style['grid-column'] = "2 / span last first" should not set the property value
Pass e.style['grid-column'] = "span 1 last first / 1" should not set the property value
Pass e.style['grid-column'] = "2 / span last 3 first" should not set the property value
Pass e.style['grid-column'] = "1 span 2 first / 1" should not set the property value
Pass e.style['grid-column'] = "2 / 3 span 3 first" should not set the property value
Pass e.style['grid-column'] = "span -1 / -2" should not set the property value
Pass e.style['grid-column'] = "-1 / -2 span" should not set the property value
Pass e.style['grid-column'] = "0 span / 0" should not set the property value
Pass e.style['grid-column'] = "0 / span 0" should not set the property value
Pass e.style['grid-column'] = "span -3 'first' / 3 last" should not set the property value
Pass e.style['grid-column'] = "first span 1 / last" should not set the property value
Pass e.style['grid-column'] = "3 first / 2 span last" should not set the property value
Pass e.style['grid-column'] = "3 / 1 span 2" should not set the property value

View file

@ -2,36 +2,35 @@ Harness status: OK
Found 31 tests
1 Pass
30 Fail
31 Pass
Pass e.style['grid-row'] = "5 8" should not set the property value
Fail e.style['grid-row'] = "5 /" should not set the property value
Fail e.style['grid-row'] = "8 auto" should not set the property value
Fail e.style['grid-row'] = "8 / /" should not set the property value
Fail e.style['grid-row'] = "0 / 6" should not set the property value
Fail e.style['grid-row'] = "8 / 0" should not set the property value
Fail e.style['grid-row'] = "0" should not set the property value
Fail e.style['grid-row'] = "span" should not set the property value
Fail e.style['grid-row'] = "span / span" should not set the property value
Fail e.style['grid-row'] = "span span / span span" should not set the property value
Fail e.style['grid-row'] = "4 4 / 3 span" should not set the property value
Fail e.style['grid-row'] = "first 4 last / 3 span" should not set the property value
Fail e.style['grid-row'] = "4 / first 3 last" should not set the property value
Fail e.style['grid-row'] = "first last / 3 span" should not set the property value
Fail e.style['grid-row'] = "4 / first last" should not set the property value
Fail e.style['grid-row'] = "span 4 4 / 3" should not set the property value
Fail e.style['grid-row'] = "5 span 4 / 3" should not set the property value
Fail e.style['grid-row'] = "span first last / 3" should not set the property value
Fail e.style['grid-row'] = "3 / span first last" should not set the property value
Fail e.style['grid-row'] = "span first last 7 / 3" should not set the property value
Fail e.style['grid-row'] = "3 / span first 5 last" should not set the property value
Fail e.style['grid-row'] = "1 span last 7 / 3" should not set the property value
Fail e.style['grid-row'] = "3 / 5 span first 5" should not set the property value
Fail e.style['grid-row'] = "-3 span / -4" should not set the property value
Fail e.style['grid-row'] = "-3 / span -4" should not set the property value
Fail e.style['grid-row'] = "span 0 / 0" should not set the property value
Fail e.style['grid-row'] = "0 / 0 span" should not set the property value
Fail e.style['grid-row'] = "last -2 span / 1 nav" should not set the property value
Fail e.style['grid-row'] = "2 span first / last" should not set the property value
Fail e.style['grid-row'] = "5 nav / last span 7" should not set the property value
Fail e.style['grid-row'] = "5 / 3 span 3" should not set the property value
Pass e.style['grid-row'] = "5 /" should not set the property value
Pass e.style['grid-row'] = "8 auto" should not set the property value
Pass e.style['grid-row'] = "8 / /" should not set the property value
Pass e.style['grid-row'] = "0 / 6" should not set the property value
Pass e.style['grid-row'] = "8 / 0" should not set the property value
Pass e.style['grid-row'] = "0" should not set the property value
Pass e.style['grid-row'] = "span" should not set the property value
Pass e.style['grid-row'] = "span / span" should not set the property value
Pass e.style['grid-row'] = "span span / span span" should not set the property value
Pass e.style['grid-row'] = "4 4 / 3 span" should not set the property value
Pass e.style['grid-row'] = "first 4 last / 3 span" should not set the property value
Pass e.style['grid-row'] = "4 / first 3 last" should not set the property value
Pass e.style['grid-row'] = "first last / 3 span" should not set the property value
Pass e.style['grid-row'] = "4 / first last" should not set the property value
Pass e.style['grid-row'] = "span 4 4 / 3" should not set the property value
Pass e.style['grid-row'] = "5 span 4 / 3" should not set the property value
Pass e.style['grid-row'] = "span first last / 3" should not set the property value
Pass e.style['grid-row'] = "3 / span first last" should not set the property value
Pass e.style['grid-row'] = "span first last 7 / 3" should not set the property value
Pass e.style['grid-row'] = "3 / span first 5 last" should not set the property value
Pass e.style['grid-row'] = "1 span last 7 / 3" should not set the property value
Pass e.style['grid-row'] = "3 / 5 span first 5" should not set the property value
Pass e.style['grid-row'] = "-3 span / -4" should not set the property value
Pass e.style['grid-row'] = "-3 / span -4" should not set the property value
Pass e.style['grid-row'] = "span 0 / 0" should not set the property value
Pass e.style['grid-row'] = "0 / 0 span" should not set the property value
Pass e.style['grid-row'] = "last -2 span / 1 nav" should not set the property value
Pass e.style['grid-row'] = "2 span first / last" should not set the property value
Pass e.style['grid-row'] = "5 nav / last span 7" should not set the property value
Pass e.style['grid-row'] = "5 / 3 span 3" should not set the property value