From 5a9094a70a89204c9c7b3efcc3bef8a4532b356f Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 8 Feb 2021 01:02:33 +0100 Subject: [PATCH] LibWeb: Make getElementsByTagName() case-insensitive for HTML elements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 91b89e4bc5..d636e90d40 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -487,10 +487,15 @@ NonnullRefPtrVector Document::get_elements_by_name(const String& name) NonnullRefPtrVector Document::get_elements_by_tag_name(const FlyString& tag_name) const { + // FIXME: Support "*" for tag_name + // https://dom.spec.whatwg.org/#concept-getelementsbytagname NonnullRefPtrVector elements; for_each_in_subtree_of_type([&](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;