From af60e361228f4b6d18112fb22d5b42db57f561ad Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 3 Jul 2025 06:21:50 +0100 Subject: [PATCH] LibWeb/CSS: Don't remove whitespace early when parsing descriptor values --- .../LibWeb/CSS/Parser/DescriptorParsing.cpp | 9 ++++---- .../css/css-syntax/urange-parsing.txt | 22 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Libraries/LibWeb/CSS/Parser/DescriptorParsing.cpp b/Libraries/LibWeb/CSS/Parser/DescriptorParsing.cpp index 199e39d19ee..bdf50d7c9b2 100644 --- a/Libraries/LibWeb/CSS/Parser/DescriptorParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/DescriptorParsing.cpp @@ -30,11 +30,7 @@ Parser::ParseErrorOr> Parser::parse_descripto if (unprocessed_tokens.peek_token().is(Token::Type::Semicolon)) break; - // FIXME: Stop removing whitespace here. It's just for compatibility with the property-parsing code. auto const& token = unprocessed_tokens.consume_a_token(); - if (token.is(Token::Type::Whitespace)) - continue; - component_values.append(token); } @@ -64,6 +60,7 @@ Parser::ParseErrorOr> Parser::parse_descripto case DescriptorMetadata::ValueType::CropOrCross: { // crop || cross auto first = parse_keyword_value(tokens); + tokens.discard_whitespace(); auto second = parse_keyword_value(tokens); if (!first) @@ -135,6 +132,8 @@ Parser::ParseErrorOr> Parser::parse_descripto if (first_length->is_length() && first_length->as_length().length().raw_value() < 0) return nullptr; + tokens.discard_whitespace(); + if (auto second_length = parse_length_value(tokens)) { if (second_length->is_length() && second_length->as_length().length().raw_value() < 0) return nullptr; @@ -160,6 +159,8 @@ Parser::ParseErrorOr> Parser::parse_descripto return nullptr; } + tokens.discard_whitespace(); + if (auto second_keyword = parse_keyword_value(tokens)) { if (orientation.is_null() && first_is_one_of(second_keyword->to_keyword(), Keyword::Landscape, Keyword::Portrait)) { orientation = second_keyword.release_nonnull(); diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-syntax/urange-parsing.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-syntax/urange-parsing.txt index 32f31591d7d..d7c89c88743 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-syntax/urange-parsing.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-syntax/urange-parsing.txt @@ -2,18 +2,18 @@ Harness status: OK Found 95 tests -92 Pass -3 Fail -Pass "u/**/+/**/a/**/?" => "U+A0-AF" +89 Pass +6 Fail +Fail "u/**/+/**/a/**/?" => "U+A0-AF" Pass "u+abc" => "U+ABC" Pass "U+abc" => "U+ABC" Pass "u+ABC" => "U+ABC" Pass "U+ABC" => "U+ABC" Pass "u+AbC" => "U+ABC" Pass "u+efg" is invalid -Fail "u+ abc" is invalid -Fail "u +abc" is invalid -Fail "u + abc" is invalid +Pass "u+ abc" is invalid +Pass "u +abc" is invalid +Pass "u + abc" is invalid Pass "U + a b c" is invalid Pass "u+a" => "U+A" Pass "u+aa" => "U+AA" @@ -34,7 +34,7 @@ Pass "u+a??????" is invalid Pass "u+a?a" is invalid Pass "u+aaaaaa" is invalid Pass "u+a?????" is invalid -Pass "u/**/+0a/**/?" => "U+A0-AF" +Fail "u/**/+0a/**/?" => "U+A0-AF" Pass "u+0a" => "U+A" Pass "U+0a0" => "U+A0" Pass "u+0aaaaa" => "U+AAAAA" @@ -51,7 +51,7 @@ Pass "u+0a?????" is invalid Pass "u+00a????" is invalid Pass "u+22222a" is invalid Pass "u+1e9a" => "U+1E9A" -Pass "u/**/+0/**/?" => "U+0-F" +Fail "u/**/+0/**/?" => "U+0-F" Pass "u/**/0" is invalid Pass "u+0" => "U+0" Pass "u+00" => "U+0" @@ -70,7 +70,7 @@ Pass "u+1e3" => "U+1E3" Pass "u+1e-20" => "U+1E-20" Pass "u+222222" is invalid Pass "u+2?????" is invalid -Pass "u/**/+0/**/-0a" => "U+0-A" +Fail "u/**/+0/**/-0a" => "U+0-A" Pass "u+0-0a" => "U+0-A" Pass "u+000000-0aaaaa" => "U+0-AAAAA" Pass "u+0000000-0a" is invalid @@ -80,7 +80,7 @@ Pass "u+0+0a" is invalid Pass "u+0?-0a" is invalid Pass "u+0-0a?" is invalid Pass "u+222222-22222a" is invalid -Pass "u/**/+0/**/-1" => "U+0-1" +Fail "u/**/+0/**/-1" => "U+0-1" Pass "u+0-1" => "U+0-1" Pass "u-0-1" is invalid Pass "u-0+1" is invalid @@ -91,7 +91,7 @@ Pass "u+0-0000001" is invalid Pass "u+0-10ffff" => "U+0-10FFFF" Pass "u+0-110000" is invalid Pass "u+0-222222" is invalid -Pass "u/**/+/**/?" => "U+0-F" +Fail "u/**/+/**/?" => "U+0-F" Pass "u+?" => "U+0-F" Pass "u+?????" => "u+0-FFFFF" Pass "u+???????" is invalid