Skip to content

Rebind copied tree ownership to the returned copy - #160

Open
ac1982 wants to merge 1 commit into
beevik:mainfrom
ac1982:fix/copied-attribute-owners
Open

ac1982 wants to merge 1 commit into
beevik:mainfrom
ac1982:fix/copied-attribute-owners

Conversation

@ac1982

@ac1982 ac1982 commented Oct 10, 2026

Copy link
Copy Markdown

Copying an element currently copies each attribute's owner pointer, so copied.SelectAttr("p:id").Element() returns the original node. Namespace lookup after editing the copy still consults the original tree, and edits through that owner mutate the original. Document copies also leave top-level tokens attached to a temporary copied container, so removing a copied root does not remove it from the returned document.

Rebind copied attributes to their new element, and rebind the document's direct tokens/attributes after embedding its copied container. Reset an isolated element copy's index to -1, consistent with its nil parent.

Regressions cover element/document copies, copied descendant attributes, namespace changes, edits through Attr.Element(), top-level comments/processing instructions, removal of a copied root, and the detached root index. They fail before their fixes and pass afterward. Full go test ./..., go test -race ./..., go vet ./..., go build ./..., and git diff --check pass on Go 1.27.1 / Linux arm64. Other Go versions/platforms were not run locally.

This is an independent branch from main; it does not include the implicit XML namespace fix in #159.

AI assistance: OpenAI Codex investigated, implemented, and ran these checks.

Signed-off-by: AC <ac@fabtek.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant