Skip to content

Truly independent web browser

LibWeb: Reject simple selectors after highlight pseudo-elements

Andreas Klinge5003975c369
diff --git a/Libraries/LibWeb/Rust/src/css/selector_parser.rs b/Libraries/LibWeb/Rust/src/css/selector_parser.rs
index 7642f422984..79abd08af0a 100644
--- a/Libraries/LibWeb/Rust/src/css/selector_parser.rs
+++ b/Libraries/LibWeb/Rust/src/css/selector_parser.rs
@@ -472,6 +472,17 @@ impl<'a> SelectorParser<'a> {
let Some(SimpleSelector::PseudoElement(pseudo_element)) = compound.simple_selectors.first() else {
continue;
};
+ // https://drafts.csswg.org/css-pseudo-4/#highlight-selectors
+ // INTEROP: Selectors 4 allows logical combination and user action pseudo-classes after any
+ // pseudo-element, but browsers reject every simple selector after a highlight pseudo-element.
+ // ::search-text is checked above, as it allows :current.
+ if matches!(
+ pseudo_element.pseudo_element,
+ PseudoElementType::Selection | PseudoElementType::SpellingError
+ ) && compound.simple_selectors.len() > 1
+ {
+ return Err(());
+ }
// https://drafts.csswg.org/css-view-transitions-1/#pseudo-root
// If a descendant pseudo of a pseudo-element root has no other siblings, then :only-child matches that
// pseudo.
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/highlight-pseudos.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/highlight-pseudos.txt
index 007c01f57d8..ca26b7c075a 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/highlight-pseudos.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/highlight-pseudos.txt
@@ -2,17 +2,17 @@ Harness status: OK
Found 40 tests
-28 Pass
-12 Fail
+32 Pass
+8 Fail
Pass "::selection" should be a valid selector
Pass ".a::selection" should be a valid selector
Pass "div ::selection" should be a valid selector
Pass "::part(my-part)::selection" should be a valid selector
Pass "::before::selection" should be an invalid selector
-Fail "::selection.a" should be an invalid selector
+Pass "::selection.a" should be an invalid selector
Pass "::selection div" should be an invalid selector
Pass "::selection::after" should be an invalid selector
-Fail "::selection:hover" should be an invalid selector
+Pass "::selection:hover" should be an invalid selector
Pass ":not(::selection)" should be an invalid selector
Fail "::target-text" should be a valid selector
Fail ".a::target-text" should be a valid selector
@@ -29,10 +29,10 @@ Pass ".a::spelling-error" should be a valid selector
Pass "div ::spelling-error" should be a valid selector
Pass "::part(my-part)::spelling-error" should be a valid selector
Pass "::before::spelling-error" should be an invalid selector
-Fail "::spelling-error.a" should be an invalid selector
+Pass "::spelling-error.a" should be an invalid selector
Pass "::spelling-error div" should be an invalid selector
Pass "::spelling-error::after" should be an invalid selector
-Fail "::spelling-error:hover" should be an invalid selector
+Pass "::spelling-error:hover" should be an invalid selector
Pass ":not(::spelling-error)" should be an invalid selector
Fail "::grammar-error" should be a valid selector
Fail ".a::grammar-error" should be a valid selector