From 219346011b5fd4c1a0a3f19087d27706fe59b8c6 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 8 Nov 2024 20:14:46 +0000 Subject: [PATCH] LibWeb/CSS: Require that tag-name simple selectors go first This fixes 1 subtest. --- .../Text/expected/wpt-import/css/css-nesting/parsing.txt | 5 ++--- Userland/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-nesting/parsing.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-nesting/parsing.txt index 2a3d0a1e70f..3b6218fd58c 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-nesting/parsing.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-nesting/parsing.txt @@ -6,8 +6,7 @@ Rerun Found 32 tests -31 Pass -1 Fail +32 Pass Details Result Test Name MessagePass .foo { & { color: green; }} Pass .foo { &.bar { color: green; }} @@ -26,7 +25,7 @@ Pass .foo { &:is(.bar, .baz) { color: green; }} Pass .foo { :is(.bar, &.baz) { color: green; }} Pass .foo { &:is(.bar, &.baz) { color: green; }} Pass .foo { div& { color: green; }} -Fail INVALID: .foo { &div { color: green; }} +Pass INVALID: .foo { &div { color: green; }} Pass .foo { .class& { color: green; }} Pass .foo { &.class { color: green; }} Pass .foo { [attr]& { color: green; }} diff --git a/Userland/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp b/Userland/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp index 94c8b2b3488..16762e45a2f 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp @@ -127,6 +127,10 @@ Parser::ParseErrorOr> Parser::parse_compoun auto component = TRY(parse_simple_selector(tokens)); if (!component.has_value()) break; + if (component->type == Selector::SimpleSelector::Type::TagName && !simple_selectors.is_empty()) { + // Tag-name selectors can only go at the beginning of a compound selector. + return ParseError::SyntaxError; + } simple_selectors.append(component.release_value()); }