Truly independent web browser
LibWeb: Look up HTML attributes case-insensitively by property name
sideshowbarker91480458f017
diff --git a/Libraries/LibWeb/DOM/NamedNodeMap.cpp b/Libraries/LibWeb/DOM/NamedNodeMap.cppindex 7c930d5df79..63b2324ef60 100644--- a/Libraries/LibWeb/DOM/NamedNodeMap.cpp+++ b/Libraries/LibWeb/DOM/NamedNodeMap.cpp@@ -95,19 +95,11 @@ Vector<Utf16FlyString> NamedNodeMap::supported_property_names() constreturn names;}-// OPTIMIZATION: A name is one of supported_property_names() if an attribute in the list has it as its qualified name,-// and it has no ASCII uppercase when the element is in the HTML namespace and its node document is an HTML-// document. Checking that directly avoids building the whole list for each name.+// AD-HOC: DOM lists only lowercase property names for HTML elements in HTML documents, but sites also read+// attributes by mixed-case names. Apply the same lookup as getNamedItem() when looking up a single property.bool NamedNodeMap::is_supported_property_name(Utf16FlyString const& name) const{- if (associated_element().namespace_uri() == Namespace::HTML && associated_element().document().is_html_document() && contains_ascii_uppercase(name.view()))- return false;-- for (size_t index = 0; index < length(); ++index) {- if (associated_element().m_attributes->at(index).name.as_string() == name)- return true;- }- return false;+ return associated_element().find_attribute_index(name).has_value();}// https://dom.spec.whatwg.org/#dom-namednodemap-itemdiff --git a/Tests/LibWeb/Text/expected/DOM/NamedNodeMap-mixed-case-lookup.txt b/Tests/LibWeb/Text/expected/DOM/NamedNodeMap-mixed-case-lookup.txtnew file mode 100644index 00000000000..f89af3112dc--- /dev/null+++ b/Tests/LibWeb/Text/expected/DOM/NamedNodeMap-mixed-case-lookup.txt@@ -0,0 +1,7 @@+value+false+missing+false+missing+false+truediff --git a/Tests/LibWeb/Text/input/DOM/NamedNodeMap-mixed-case-lookup.html b/Tests/LibWeb/Text/input/DOM/NamedNodeMap-mixed-case-lookup.htmlnew file mode 100644index 00000000000..f2a8d54fc1e--- /dev/null+++ b/Tests/LibWeb/Text/input/DOM/NamedNodeMap-mixed-case-lookup.html@@ -0,0 +1,17 @@+<!doctype html>+<script src="../include.js"></script>+<script>+ test(() => {+ const html = document.createElement("div");+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");+ const xml = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "div").documentElement;+ for (const element of [html, svg, xml]) {+ element.setAttribute("data-name", "value");+ const attributes = element.attributes;+ println(attributes["data-Name"]?.value ?? "missing");+ println(Object.getOwnPropertyNames(attributes).includes("data-Name"));+ }+ html.removeAttribute("data-name");+ println(html.attributes["data-Name"] === undefined);+ });+</script>