LibWeb: Make getElementsByTagName() case-insensitive for HTML elements

From https://dom.spec.whatwg.org/#concept-getelementsbytagname:

    2. Otherwise, if root’s node document is an HTML document, return a
       HTMLCollection rooted at root, whose filter matches the following
       descendant elements:

       * Whose namespace is the HTML namespace and whose qualified name
         is qualifiedName, in ASCII lowercase.

       * Whose namespace is not the HTML namespace and whose qualified
         name is qualifiedName.
This commit is contained in:
Linus Groh 2021-02-08 01:02:33 +01:00 committed by Andreas Kling
parent 27a395d964
commit 5a9094a70a
Notes: sideshowbarker 2024-07-18 22:31:41 +09:00

View File

@ -487,10 +487,15 @@ NonnullRefPtrVector<Element> Document::get_elements_by_name(const String& name)
NonnullRefPtrVector<Element> Document::get_elements_by_tag_name(const FlyString& tag_name) const
{
// FIXME: Support "*" for tag_name
// https://dom.spec.whatwg.org/#concept-getelementsbytagname
NonnullRefPtrVector<Element> elements;
for_each_in_subtree_of_type<Element>([&](auto& element) {
if (element.local_name() == tag_name)
if (element.namespace_() == Namespace::HTML
? element.local_name().to_lowercase() == tag_name.to_lowercase()
: element.local_name() == tag_name) {
elements.append(element);
}
return IterationDecision::Continue;
});
return elements;