Skip to content

Lightpanda: the headless browser designed for AI and automation

selector: drop pseudo-element arguments from :is and :where

Adrià Arrufat04912f593c5f
diff --git a/src/browser/tests/document/query_selector_pseudo_element.html b/src/browser/tests/document/query_selector_pseudo_element.html
index 5662c387b..13cfb6c81 100644
--- a/src/browser/tests/document/query_selector_pseudo_element.html
+++ b/src/browser/tests/document/query_selector_pseudo_element.html
@@ -4,6 +4,8 @@
.x::after { display: none; }
.hide, .x::before { display: none; }
*, ::before, ::after { --ring: 3px; }
+ :is(#d::before, .x) { display: none; }
+ .x { display: block; }
</style>
<body>
@@ -62,5 +64,7 @@
// A pseudo-element in a selector list doesn't drop the other selectors.
testing.expectFalse(document.getElementById('h').checkVisibility());
testing.expectEqual('3px', getComputedStyle(d).getPropertyValue('--ring').trim());
+
+ testing.expectEqual('block', getComputedStyle(d).display);
}
</script>
diff --git a/src/browser/webapi/selector/Parser.zig b/src/browser/webapi/selector/Parser.zig
index 3d81086fe..2a4345a8a 100644
--- a/src/browser/webapi/selector/Parser.zig
+++ b/src/browser/webapi/selector/Parser.zig
@@ -602,7 +602,8 @@ fn pseudoClass(self: *Parser, arena: Allocator) !Selector.PseudoClass {
if (self.peek() == 0) return error.InvalidPseudoClass;
const selector = try parse(arena, self.consumeUntilCommaOrParen());
- try selectors.append(arena, selector);
+ // Invalid here, so the forgiving list drops it.
+ if (!selector.hasPseudoElement()) try selectors.append(arena, selector);
_ = self.skipSpaces();
if (self.peek() == ',') {
@@ -629,7 +630,7 @@ fn pseudoClass(self: *Parser, arena: Allocator) !Selector.PseudoClass {
if (self.peek() == 0) return error.InvalidPseudoClass;
const selector = try parse(arena, self.consumeUntilCommaOrParen());
- try selectors.append(arena, selector);
+ if (!selector.hasPseudoElement()) try selectors.append(arena, selector);
_ = self.skipSpaces();
if (self.peek() == ',') {