LibWeb: Treat CSS selectors containing undeclared namespaces as invalid

Selectors containing undeclared namespaces should be considered invalid,
not just not matching any elements.

Gains us 3 new WPT passes.
This commit is contained in:
Callum Law 2025-06-23 22:40:37 +12:00 committed by Sam Atkins
commit 6584ae0080
Notes: github-actions[bot] 2025-06-24 11:52:28 +00:00
17 changed files with 157 additions and 11 deletions

View file

@ -126,12 +126,17 @@ void CSSStyleRule::set_selector_text(StringView selector_text)
clear_caches();
// 1. Run the parse a group of selectors algorithm on the given value.
Parser::ParsingParams parsing_params { realm() };
if (m_parent_style_sheet)
parsing_params.declared_namespaces = m_parent_style_sheet->declared_namespaces();
Optional<SelectorList> parsed_selectors;
if (parent_style_rule()) {
// AD-HOC: If we're a nested style rule, then we need to parse the selector as relative and then adapt it with implicit &s.
parsed_selectors = parse_selector_for_nested_style_rule(Parser::ParsingParams { realm() }, selector_text);
parsed_selectors = parse_selector_for_nested_style_rule(parsing_params, selector_text);
} else {
parsed_selectors = parse_selector(Parser::ParsingParams { realm() }, selector_text);
parsed_selectors = parse_selector(parsing_params, selector_text);
}
// 2. If the algorithm returns a non-null value replace the associated group of selectors with the returned value.