fix: [#2229] Fix Element.setAttribute() to accept names containing a colon (e.g. hx-on:click) - #2241
Open
marciomazza wants to merge 2 commits into
Open
fix: [#2229] Fix Element.setAttribute() to accept names containing a colon (e.g. hx-on:click)#2241marciomazza wants to merge 2 commits into
marciomazza wants to merge 2 commits into
Conversation
…n in the name Per spec, only createAttributeNS()/setAttributeNS() split a qualified name on ':' into prefix/localName. The plain (non-NS) createAttribute() must keep the whole name as localName with no prefix and no namespace. Splitting unconditionally made NamedNodeMap#getNamedItemNS() unable to find the previous attribute to replace (its 'prefix without namespaceURI' guard correctly rejects malformed input, but createAttribute() was manufacturing exactly that malformed shape). setNamedItem() would then append instead of replace, so getAttribute() on any colon-containing attribute name (e.g. hx-on:click, used by htmx) kept returning the first value ever set, no matter how many times setAttribute() was called afterward.
marciomazza
force-pushed
the
fix/attr-name-colon-prefix
branch
from
September 4, 2026 20:31
0575e36 to
18efd79
Compare
…ttributeNS
Element.test.ts:1870 and NamedNodeMap.test.ts:54/114 were titled around
'different prefix' but used plain setAttribute('ns1:key', ...), which never
namespaces anything - after the createAttribute() fix those calls just
produce two unrelated attribute names that happen to contain colons.
Rewrite them to use setAttributeNS() with distinct namespaces so they
actually exercise the same-localName/different-prefix/different-namespace
case, which had no coverage anywhere else in the suite.
marciomazza
force-pushed
the
fix/attr-name-colon-prefix
branch
from
September 8, 2026 14:19
18efd79 to
3cd1cde
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Resolves #2229
Document.createAttribute()(and, through it,Element.setAttribute()'s HTML-namespace path) was splitting the qualified name on:intoprefix/localName, even though that's only correct forcreateAttributeNS()/setAttributeNS(). Per spec, plaincreateAttribute()must keep the qualified name whole, withprefix = nulland no namespace.This produced an
Attrwith aprefixbut nonamespaceURI— a combinationNamedNodeMap#getNamedItemNS()correctly refuses to resolve, since real namespaced attributes always have both. That madesetNamedItem()unable to find the previous attribute to replace, so it kept appending instead of overwriting:getAttribute()on any colon-containing, non-namespaced attribute name (e.g.hx-on:click, used by htmx 4, or any customfoo:bar-style attribute) would forever return the very first value ever set viasetAttribute(), no matter how many times it was called afterward.Fix:
createAttribute()now always setslocalNameto the full qualified name andprefixtonull, matching the DOM spec and real browser behavior.createAttributeNS()/setAttributeNS()are untouched — they already implement the namespace-aware split correctly.Also tidied up three existing tests (
Element.test.ts/NamedNodeMap.test.ts) that were titled around "same local name, different prefix" but exercised via plainsetAttribute()— which never namespaces anything, so they weren't actually testing that case. Rewrote them to usesetAttributeNS()with real distinct namespaces, which was previously uncovered.Before submitting the PR, please make sure you do the following:
Tests
npm testlocally to make sure that all tests pass before submitting the PR.Title
feat,fix,choreorBREAKING CHANGE. The issue is optional and can be omitted if the pull request does not relate to an issue.AI disclosure
Per the project's AI Contributions policy: Claude (Anthropic) assisted in diagnosing the bug, writing the fix, and drafting this description. I guided and reviewed the change myself at every step.