LibWeb: Only return HTML elements from getElementsByName()

Fixes two WPT tests:
document.getElementsByName-namespace-xhtml.xhtml and
document.getElementsByName-namespace.html
This commit is contained in:
ronak69 2024-10-14 13:16:10 +00:00 committed by Andreas Kling
commit 917a2a3c86
Notes: github-actions[bot] 2024-10-14 16:00:15 +00:00
3 changed files with 25 additions and 2 deletions

View file

@ -1488,12 +1488,13 @@ void Document::set_hovered_node(Node* node)
}
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-getelementsbyname
JS::NonnullGCPtr<NodeList> Document::get_elements_by_name(FlyString const& name)
{
return LiveNodeList::create(realm(), *this, LiveNodeList::Scope::Descendants, [name](auto const& node) {
if (!is<Element>(node))
if (!is<HTML::HTMLElement>(node))
return false;
return verify_cast<Element>(node).name() == name;
return verify_cast<HTML::HTMLElement>(node).name() == name;
});
}