LibWeb: Don't fail on non-fill keyword parsing <border-image-slice>

Previously if we encountered a keyword other than `fill` when parsing
`<border-image-slice` we would return a nullptr.

This could cause issues when we parse `<border-image-slice>` as part of
parsing `border-image`, for example `border-image: 100% none` would fail
as we would try parse `none` as part of the `<border-image-slice>`
instead of `<border-image-source>`.

This change makes it so that we don't consume the token and leave it to
be parsed as part of the next section of the grammar.
This commit is contained in:
Callum Law 2025-07-10 03:20:10 +12:00 committed by Tim Ledbetter
parent cfafb3bf36
commit a8fc15c6b3
Notes: github-actions[bot] 2025-07-09 16:00:34 +00:00
3 changed files with 21 additions and 13 deletions

View file

@ -1792,19 +1792,15 @@ RefPtr<CSSStyleValue const> Parser::parse_border_image_slice_value(TokenStream<C
RefPtr<CSSStyleValue const> bottom;
RefPtr<CSSStyleValue const> left;
auto parse_fill = [&](TokenStream<ComponentValue>& fill_tokens) -> Optional<bool> {
if (auto keyword = parse_keyword_value(fill_tokens)) {
if (fill || keyword->to_keyword() != Keyword::Fill)
return {};
auto parse_fill = [](TokenStream<ComponentValue>& fill_tokens) {
if (fill_tokens.next_token().is_ident("fill"sv)) {
fill_tokens.discard_a_token();
return true;
}
return false;
};
auto maybe_fill_value = parse_fill(tokens);
if (!maybe_fill_value.has_value())
return nullptr;
if (*maybe_fill_value)
if (parse_fill(tokens))
fill = true;
Vector<ValueComparingNonnullRefPtr<CSSStyleValue const>> number_percentages;
@ -1849,12 +1845,11 @@ RefPtr<CSSStyleValue const> Parser::parse_border_image_slice_value(TokenStream<C
return nullptr;
}
if (tokens.has_next_token()) {
maybe_fill_value = parse_fill(tokens);
if (!maybe_fill_value.has_value())
if (tokens.has_next_token() && parse_fill(tokens)) {
if (fill)
return nullptr;
if (*maybe_fill_value)
fill = true;
fill = true;
}
transaction.commit();