Ver Fonte

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.
Linus Groh há 4 anos atrás
pai
commit
5a9094a70a
1 ficheiros alterados com 6 adições e 1 exclusões
  1. 6 1
      Userland/Libraries/LibWeb/DOM/Document.cpp

+ 6 - 1
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -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;