From ef48d967d446f1bf4f961fc0786098b819b42914 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Mon, 4 Dec 2023 15:32:45 +0000 Subject: [PATCH] LibWeb: Correct parsing of background-position 3-value syntax There were two bugs here, one of which hid the other: - Only one offset would have a value, but we dereferenced both. - We consumed a token whether it was a valid offset or not. --- .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 9249985c8b..ceb732c18b 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -2554,8 +2554,13 @@ RefPtr Parser::parse_position_value(TokenStream vertical_edge; Optional vertical_offset; + auto matches = [&]() { + return horizontal_edge.has_value() && vertical_edge.has_value() + && horizontal_offset.has_value() != vertical_offset.has_value(); + }; + auto parse_horizontal = [&] { - // [ left | right ] ] + // [ left | right ] ? auto transaction = tokens.begin_transaction(); tokens.skip_whitespace(); auto edge = parse_position_edge(tokens.next_token()); @@ -2564,16 +2569,17 @@ RefPtr Parser::parse_position_value(TokenStream ] + // [ top | bottom ] ? auto transaction = tokens.begin_transaction(); tokens.skip_whitespace(); auto edge = parse_position_edge(tokens.next_token()); @@ -2582,17 +2588,20 @@ RefPtr Parser::parse_position_value(TokenStream Parser::parse_position_value(TokenStream