From 64f09b520de7170825f94cc61972614a72964d63 Mon Sep 17 00:00:00 2001 From: Callum Law Date: Fri, 23 May 2025 00:07:03 +1200 Subject: [PATCH] LibWeb: Be less aggressive in marking elements as not being named When an element's ID is removed we only want to remove it from `m_potentially_named_elements` if it is not also considered a potentially named element due to it's name content attribute. --- Libraries/LibWeb/DOM/Document.cpp | 2 +- .../dom-tree-accessors/nameditem-01.txt | 12 ++ .../dom-tree-accessors/nameditem-01.html | 118 ++++++++++++++++++ 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.html diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index a46502dcd03..85eac1dd055 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -5440,7 +5440,7 @@ void Document::element_id_changed(Badge, GC::Ref ele if (element->id().has_value()) insert_in_tree_order(m_potentially_named_elements, element); - else + else if (!element->name().has_value()) (void)m_potentially_named_elements.remove_first_matching([element](auto& e) { return e == element; }); auto new_id = element->id(); diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.txt new file mode 100644 index 00000000000..34a41e6f379 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.txt @@ -0,0 +1,12 @@ +Harness status: OK + +Found 7 tests + +7 Pass +Pass img elements that have a name and id attribute, should be accessible by both values. +Pass img elements that have a name and id attribute with same value. +Pass Dynamically removing the name attribute from img elements, should not be accessible. +Pass Dynamically removing the id attribute from img elements, should still be accessible by name value. +Pass Dynamically updating the name attribute from img elements, should be accessible by values. +Pass Dynamically updating the id attribute from img elements, should be accessible by values. +Pass img elements that is removed, should not be accessible. \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.html new file mode 100644 index 00000000000..2e8c1f2ce13 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.html @@ -0,0 +1,118 @@ + + +Named items: img id & name + + + + +
+
+ + + + + + + +
+