LibWeb: Correctly handle serialization of PseudoElements

Previusly the implementation only was serializing PseudoElements if they
were the last element in the CompoundSelector. This caused bugs on
Javascript code that referenced their selectorText, where it would be
wrong.
This commit is contained in:
Luiz 2025-06-22 21:12:25 -03:00 committed by Sam Atkins
commit da14e072b7
Notes: github-actions[bot] 2025-06-24 11:46:10 +00:00
3 changed files with 23 additions and 4 deletions

View file

@ -475,7 +475,8 @@ String Selector::SimpleSelector::serialize() const
break;
}
case Selector::SimpleSelector::Type::PseudoElement:
// Note: Pseudo-elements are dealt with in Selector::serialize()
// AD-HOC: Spec issue: https://github.com/w3c/csswg-drafts/issues/11997
s.append(this->pseudo_element().serialize());
break;
case Type::Nesting:
// AD-HOC: Not in spec yet.
@ -572,9 +573,8 @@ String Selector::serialize() const
} else {
// 4. If this is the last part of the chain of the selector and there is a pseudo-element,
// append "::" followed by the name of the pseudo-element, to s.
if (compound_selector.simple_selectors.last().type == Selector::SimpleSelector::Type::PseudoElement) {
s.append(compound_selector.simple_selectors.last().pseudo_element().serialize());
}
// This algorithm has a problem, see https://github.com/w3c/csswg-drafts/issues/11997
// serialization of pseudoElements was moved to SimpleSelector::serialize()
}
}

View file

@ -0,0 +1,2 @@
::-webkit-scrollbar-thumb
::-webkit-scrollbar-thumb:hover

View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<style>
::-webkit-scrollbar-thumb {
background: #28bea5;
}
::-webkit-scrollbar-thumb:hover {
background: #28bea5;
}
</style>
<script src="../include.js"></script>
<script>
test(() => {
for (let rule of document.styleSheets[0].cssRules) {
println(rule.selectorText);
}
});
</script>