LibWeb: Parse identifiers last in parse_paint_value()

Previously, using an identifier color like `currentColor` would fail to
parse, since we look at ident tokens (and reject unrecognised ones)
before trying to parse colors.
This commit is contained in:
Sam Atkins 2023-06-16 14:12:18 +01:00 committed by Andreas Kling
parent a988241f3f
commit 8ef25989b6
Notes: sideshowbarker 2024-07-18 00:54:03 +09:00

View file

@ -4657,6 +4657,18 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_paint_value(TokenStream<ComponentValue
{
// `<paint> = none | <color> | <url> [none | <color>]? | context-fill | context-stroke`
if (auto color = TRY(parse_color_value(tokens.peek_token()))) {
(void)tokens.next_token();
return color;
}
if (auto url = TRY(parse_url_value(tokens.peek_token(), AllowedDataUrlType::Image))) {
// FIXME: Accept `[none | <color>]?`
(void)tokens.next_token();
return url;
}
// NOTE: <color> also accepts identifiers, so we do this identifier check last.
if (tokens.peek_token().is(Token::Type::Ident)) {
auto maybe_ident = value_id_from_string(tokens.peek_token().token().ident());
if (maybe_ident.has_value()) {
@ -4671,17 +4683,6 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_paint_value(TokenStream<ComponentValue
}
}
if (auto color = TRY(parse_color_value(tokens.peek_token()))) {
(void)tokens.next_token();
return color;
}
if (auto url = TRY(parse_url_value(tokens.peek_token(), AllowedDataUrlType::Image))) {
// FIXME: Accept `[none | <color>]?`
(void)tokens.next_token();
return url;
}
return nullptr;
}