LibWeb: Reject selectors with named namespaces in querySelectorAll

This commit is contained in:
Gingeh 2024-11-21 21:31:39 +11:00 committed by Andreas Kling
parent ba0cc7fe46
commit bb678e75f9
Notes: github-actions[bot] 2024-11-23 08:51:25 +00:00
2 changed files with 46 additions and 22 deletions

View file

@ -23,6 +23,26 @@ namespace Web::DOM {
GC_DEFINE_ALLOCATOR(ParentNode);
static bool contains_named_namespace(const CSS::SelectorList& selectors)
{
for (auto const& selector : selectors) {
for (auto const& compound_selector : selector->compound_selectors()) {
for (auto simple_selector : compound_selector.simple_selectors) {
if (simple_selector.value.has<CSS::Selector::SimpleSelector::QualifiedName>()) {
if (simple_selector.qualified_name().namespace_type == CSS::Selector::SimpleSelector::QualifiedName::NamespaceType::Named)
return true;
}
if (simple_selector.value.has<CSS::Selector::SimpleSelector::PseudoClassSelector>()) {
if (contains_named_namespace(simple_selector.pseudo_class().argument_selector_list))
return true;
}
}
}
}
return false;
}
enum class ReturnMatches {
First,
All,
@ -40,6 +60,10 @@ static WebIDL::ExceptionOr<Variant<GC::Ptr<Element>, GC::Ref<NodeList>>> scope_m
auto selectors = maybe_selectors.value();
// "Note: Support for namespaces within selectors is not planned and will not be added."
if (contains_named_namespace(selectors))
return WebIDL::SyntaxError::create(node.realm(), "Failed to parse selector"_string);
// 3. Return the result of match a selector against a tree with s and nodes root using scoping root node.
GC::Ptr<Element> single_result;
Vector<GC::Root<Node>> results;