Skip to content

Truly independent web browser

LibWeb: Reject a universal selector after another simple selector

Andreas Kling89d063684587
diff --git a/Libraries/LibWeb/Rust/src/css/selector_parser.rs b/Libraries/LibWeb/Rust/src/css/selector_parser.rs
index 02bf280db9e..3bc100563b5 100644
--- a/Libraries/LibWeb/Rust/src/css/selector_parser.rs
+++ b/Libraries/LibWeb/Rust/src/css/selector_parser.rs
@@ -1110,7 +1110,11 @@ impl<'a> SelectorParser<'a> {
fn parse_compound_simple_selectors(&mut self, stream: &mut Stream<'_>) -> Result<Vec<SimpleSelector>, ()> {
let mut simple_selectors = Vec::new();
while let Some(simple_selector) = self.parse_simple_selector(stream)? {
- if matches!(simple_selector, SimpleSelector::TagName(_)) && !simple_selectors.is_empty() {
+ if matches!(
+ simple_selector,
+ SimpleSelector::TagName(_) | SimpleSelector::Universal(_)
+ ) && !simple_selectors.is_empty()
+ {
return Err(());
}
if let SimpleSelector::PseudoElement(pseudo_element) = &simple_selector {
diff --git a/Tests/LibWeb/Text/expected/css/selector-universal-after-another-simple-selector.txt b/Tests/LibWeb/Text/expected/css/selector-universal-after-another-simple-selector.txt
index d47a855a131..ecc10eb1807 100644
--- a/Tests/LibWeb/Text/expected/css/selector-universal-after-another-simple-selector.txt
+++ b/Tests/LibWeb/Text/expected/css/selector-universal-after-another-simple-selector.txt
@@ -5,19 +5,19 @@
*[id]: parses, supports true
*:first-child: parses, supports true
*::before: parses, supports true
-**: parses, supports true
-div*: parses, supports true
+**: SyntaxError, supports false
+div*: SyntaxError, supports false
*div: SyntaxError, supports false
-*|**: parses, supports true
-*|*|*: parses, supports true
-|*|*: parses, supports true
-*|div*: parses, supports true
-.a*: parses, supports true
-#target*: parses, supports true
-[id]*: parses, supports true
-:first-child*: parses, supports true
-*[id]*: parses, supports true
-::before*: parses, supports true
+*|**: SyntaxError, supports false
+*|*|*: SyntaxError, supports false
+|*|*: SyntaxError, supports false
+*|div*: SyntaxError, supports false
+.a*: SyntaxError, supports false
+#target*: SyntaxError, supports false
+[id]*: SyntaxError, supports false
+:first-child*: SyntaxError, supports false
+*[id]*: SyntaxError, supports false
+::before*: SyntaxError, supports false
div *: parses, supports true
div > *: parses, supports true
-color rgb(1, 0, 0), background-color rgb(2, 0, 0), margin-left 3px, margin-right 4px
+color rgb(0, 0, 0), background-color rgba(0, 0, 0, 0), margin-left 0px, margin-right 4px