fix(js): make setAttributeNS/getAttributeNS/removeAttributeNS namespace-aware
The three NS methods ignored the namespace: setAttributeNS stored the qualified name against the non-namespaced store and getAttributeNS/removeAttributeNS looked up by local name only, so a namespaced attribute was not addressable by (namespace, localName) — getAttributeNS(xlink, 'href') returned null. Record the namespace on the attribute and add namespace-aware DOM ops that match by (namespace, localName), where the local name is the attribute name after any prefix (so both setAttributeNS-created 'xlink:href' and parser-created 'href' resolve). The non-namespaced getAttribute/serialization paths are untouched, and getAttributeNS(null, name) still reads plain attributes. Fixes #503
This commit is contained in:
1 parent
8078cc3070
commit
6314ecbf88
4 files changed
+114
-3
No files matched your search
Vendored
+3
-3
@@ -1352,9 +1352,9 @@ class Element extends Node {
|
||||
if (popoverPrev !== undefined) this._popoverTypeMaybeChanged(popoverPrev);
|
||||
if (globalThis.__mutationObservers?.length) globalThis.__notifyMutation('attributes', this._nid, [], [], n);
|
||||
}
|
||||
setAttributeNS(ns, n, v) { _dom("set_attribute", this._nid, String(n) + "\0" + String(v)); } // exact name, no HTML folding
|
||||
setAttributeNS(ns, n, v) { _dom("set_attribute_ns", this._nid, String(ns == null ? "" : ns) + "\0" + String(n) + "\0" + String(v)); } // n is the qualified name; stored with its namespace
|
||||
removeAttribute(n) { n = _htmlAttrName(this, n); const popoverPrev = (n === "popover") ? this.popover : undefined; _dom("remove_attribute", this._nid, n); if (popoverPrev !== undefined) this._popoverTypeMaybeChanged(popoverPrev); }
|
||||
removeAttributeNS(ns, n) { _dom("remove_attribute", this._nid, String(n)); }
|
||||
removeAttributeNS(ns, n) { _dom("remove_attribute_ns", this._nid, String(ns == null ? "" : ns) + "\0" + String(n)); }
|
||||
hasAttribute(n) { return this.getAttribute(n) !== null; }
|
||||
hasAttributes() { return true; } // Simplified
|
||||
getAttributeNames() { return _domParse("attribute_names", this._nid) || []; }
|
||||
@@ -1386,7 +1386,7 @@ class Element extends Node {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
getAttributeNS(ns, n) { return _domParse("get_attribute", this._nid, String(n)); }
|
||||
getAttributeNS(ns, n) { return _domParse("get_attribute_ns", this._nid, String(ns == null ? "" : ns) + "\0" + String(n)); }
|
||||
querySelector(s) { return _wrapEl(+_dom("query_selector_scoped", this._nid, s)); }
|
||||
querySelectorAll(s) {
|
||||
const ids = _domParse("query_selector_all_scoped", this._nid, s) || [];
|
||||
|
||||
Reference in new issue
Block a user