fix: preserve namespace declarations during reconciliation (closes #78)#175
Draft
toddr-bot wants to merge 1 commit into
Draft
fix: preserve namespace declarations during reconciliation (closes #78)#175toddr-bot wants to merge 1 commit into
toddr-bot wants to merge 1 commit into
Conversation
domReconcileNs previously removed namespace declarations from a node's nsDef list when the same prefix->URI mapping existed on an ancestor. While the full document serialization remained correct, toString() on the affected subtree would produce XML with undeclared namespace prefixes — e.g. <saml:Assertion xmlns="foobar"> missing xmlns:saml. The fix simplifies reconciliation: instead of searching ancestors and stripping matching declarations, each node simply ensures its own namespace has a local declaration in nsDef. If the ns is already local, it's left alone. If it points to a foreign struct (e.g. after a cross-document move), a local copy is created. This removes _domAddNsChain and the unused-ns freeing machinery, which are no longer needed since declarations are preserved rather than collected for deferred freeing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
What
Fixes replaceNode (and appendChild, insertBefore) dropping namespace
declarations, causing toString to emit XML with undeclared prefixes.
Why
GH #78: when a node with
xmlns:saml="foobar"is inserted under a parentthat already declares the same prefix,
domReconcileNsremoved the localdeclaration and repointed
tree->nsto the ancestor's. While semanticallycorrect for the full document tree,
xmlNodeDump(used bytoString)only emits declarations from the node's own
nsDeflist — so the prefixdisappeared from subtree serialization, producing invalid XML like
<saml:Assertion xmlns="foobar">withoutxmlns:saml.How
Simplified
_domReconcileNsto ensure each node has a local namespacedeclaration rather than stripping ones that match ancestors. If the ns
is already in the node's
nsDef, it's left untouched. If it points toa foreign struct (after cross-document move), a local copy is created.
Removed
_domAddNsChainand theunusednamespace freeing chain — nolonger needed since declarations are preserved.
The trade-off: full-document serialization now includes redundant namespace
declarations on child elements. This is valid XML and matches what many
other DOM implementations do. The DOM spec does not require stripping
redundant declarations during tree mutations.
Testing
t/48_gh78_replaceNode_ns.t(7 tests) — regression test for Namespace declaration gets removed when using replaceNode #78t/10ns.tto expect preserved declarations🤖 Generated with Claude Code
Quality Report
Changes: 3 files changed, 101 insertions(+), 97 deletions(-)
Code scan: 6 issue(s) found
t/10ns.t:428— TODO commentt/10ns.t:436— TODO commentt/10ns.t:469— TODO commentt/10ns.t:481— TODO commentt/10ns.t:497— TODO commentt/10ns.t:526— TODO commentTests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline