From 8ef25989b6ad21ed317acb9c5833e1f2c911851b Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 16 Jun 2023 14:12:18 +0100 Subject: [PATCH] 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. --- .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 3367332243..3e85ced585 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -4657,6 +4657,18 @@ ErrorOr> Parser::parse_paint_value(TokenStream = none | | [none | ]? | 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 | ]?` + (void)tokens.next_token(); + return url; + } + + // NOTE: 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> Parser::parse_paint_value(TokenStream]?` - (void)tokens.next_token(); - return url; - } - return nullptr; }