Truly independent web browser
LibWeb: Ignore namespaced rel attributes in relList
Shannon Boothcd5ade81dedc
diff --git a/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp b/Libraries/LibWeb/HTML/HTMLAnchorElement.cppindex a130fcb6e5f..4c6db462ef3 100644--- a/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp@@ -36,7 +36,7 @@ void HTMLAnchorElement::attribute_changed(Utf16FlyString const& name, Optional<Uif (name == HTML::AttributeNames::href) {href_content_attribute_changed();- } else if (name == HTML::AttributeNames::rel) {+ } else if (!namespace_.has_value() && name == HTML::AttributeNames::rel) {if (m_rel_list)m_rel_list->associated_attribute_changed(value);}diff --git a/Libraries/LibWeb/HTML/HTMLAreaElement.cpp b/Libraries/LibWeb/HTML/HTMLAreaElement.cppindex 65734201bea..d50cd6bb600 100644--- a/Libraries/LibWeb/HTML/HTMLAreaElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLAreaElement.cpp@@ -36,7 +36,7 @@ void HTMLAreaElement::attribute_changed(Utf16FlyString const& name, Optional<Utfif (name == HTML::AttributeNames::href) {href_content_attribute_changed();- } else if (name == HTML::AttributeNames::rel) {+ } else if (!namespace_.has_value() && name == HTML::AttributeNames::rel) {if (m_rel_list)m_rel_list->associated_attribute_changed(value);}diff --git a/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Libraries/LibWeb/HTML/HTMLFormElement.cppindex 8dc3bad305f..91fd0611a84 100644--- a/Libraries/LibWeb/HTML/HTMLFormElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLFormElement.cpp@@ -791,7 +791,7 @@ void HTMLFormElement::attribute_changed(Utf16FlyString const& name, Optional<Utf{Base::attribute_changed(name, old_value, value, namespace_);- if (name == HTML::AttributeNames::rel) {+ if (!namespace_.has_value() && name == HTML::AttributeNames::rel) {if (m_rel_list)m_rel_list->associated_attribute_changed(value);}diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cppindex 31e94c8ac5a..42ac12a7353 100644--- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp@@ -283,7 +283,7 @@ void HTMLLinkElement::attribute_changed(Utf16FlyString const& name, Optional<Utfstart = i + 1;}- if (m_rel_list)+ if (!namespace_.has_value() && m_rel_list)m_rel_list->associated_attribute_changed(value);// NB: A link that no longer represents a stylesheet will not run stylesheet completion steps.diff --git a/Libraries/LibWeb/SVG/SVGAElement.cpp b/Libraries/LibWeb/SVG/SVGAElement.cppindex 1f6047baa7a..f5388239cce 100644--- a/Libraries/LibWeb/SVG/SVGAElement.cpp+++ b/Libraries/LibWeb/SVG/SVGAElement.cpp@@ -42,7 +42,7 @@ void SVGAElement::attribute_changed(Utf16FlyString const& name, Optional<Utf16Stif (name == SVG::AttributeNames::href && (!namespace_.has_value() || namespace_ == Namespace::XLink))href_content_attribute_changed();- if (name == HTML::AttributeNames::rel) {+ if (!namespace_.has_value() && name == HTML::AttributeNames::rel) {if (m_rel_list)m_rel_list->associated_attribute_changed(value);}diff --git a/Tests/LibWeb/Text/expected/DOM/DOMTokenList-relList-ignores-namespaced-rel.txt b/Tests/LibWeb/Text/expected/DOM/DOMTokenList-relList-ignores-namespaced-rel.txtnew file mode 100644index 00000000000..0c24804381b--- /dev/null+++ b/Tests/LibWeb/Text/expected/DOM/DOMTokenList-relList-ignores-namespaced-rel.txt@@ -0,0 +1,5 @@+http://www.w3.org/1999/xhtml:a: after set 1 first, after removal 1 first+http://www.w3.org/1999/xhtml:area: after set 1 first, after removal 1 first+http://www.w3.org/1999/xhtml:form: after set 1 first, after removal 1 first+http://www.w3.org/1999/xhtml:link: after set 1 first, after removal 1 first+http://www.w3.org/2000/svg:a: after set 1 first, after removal 1 firstdiff --git a/Tests/LibWeb/Text/input/DOM/DOMTokenList-relList-ignores-namespaced-rel.html b/Tests/LibWeb/Text/input/DOM/DOMTokenList-relList-ignores-namespaced-rel.htmlnew file mode 100644index 00000000000..54d9ec0e64a--- /dev/null+++ b/Tests/LibWeb/Text/input/DOM/DOMTokenList-relList-ignores-namespaced-rel.html@@ -0,0 +1,16 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ test(() => {+ const elements = ["a", "area", "form", "link"].map(name => document.createElement(name));+ elements.push(document.createElementNS("http://www.w3.org/2000/svg", "a"));+ for (const element of elements) {+ element.setAttribute("rel", "first");+ const list = element.relList;+ element.setAttributeNS("urn:x", "rel", "second");+ const afterSet = `${list.length} ${list[0]}`;+ element.removeAttributeNS("urn:x", "rel");+ println(`${element.namespaceURI}:${element.localName}: after set ${afterSet}, after removal ${list.length} ${list[0]}`);+ }+ });+</script>