Repository navigation
fix: declare namespace prefixes that are not in scope when saving (#456) - #458
Merged
Merged
Conversation
Elements built in code carry no namespace declarations and relied on an ancestor declaring their prefixes. Namespaces in XML lets a producer declare a prefix on the element that uses it instead of the part root, so new `<p:sldId r:id>` / `<a:blip r:embed>` elements could be written with an unbound prefix and the saved part no longer parsed. The serializer now tracks the prefixes in scope and declares any that an element's name or attributes need. Parsed trees are unaffected: their declarations already cover every prefix. getShapeXmlString keeps writing the shape as a fragment so its output does not change. Closes #456 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <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.
Summary
Saving no longer writes an element or attribute whose namespace prefix is unbound. Edits such as
duplicateSlideandaddSlideImageaddr:id/r:embedto new elements; when the template declaredxmlns:ron individual elements rather than on the part root, the saved part did not parse and the file could not be loaded again.Motivation
Reported with a reproduction in #456. Namespaces in XML allows declaring a prefix on any ancestor of the element that uses it, and some producers do exactly that. Elements built with
elem(...)carry no declarations of their own, so they relied on the part root declaring their prefix.Closes #456
Changes
serializeXmltracks the prefix → URI bindings in scope and, on each element, declares any prefix its name or prefixed attributes use that is unbound or bound to a different URI. Declarations the input already had are written exactly as before, so parsed parts serialize byte-for-byte as before; only hand-built elements that previously produced unbound prefixes change.serializeFragment(used for comparison keys) is unchanged.getShapeXmlStringnow writes the shape as a fragment, keeping its output identical to before; it serialized a subtree as if it were a document root, which with the change above would have addedxmlns:a/xmlns:pto the shape's elements.Testing
test/issue-456-undeclared-prefix.test.ts: both reproductions from the issue (duplicate slide with per-elementxmlns:r, then save + reload and remove; image on a slide whose root omitsxmlns:r), plus serializer unit cases (declare only where needed, redeclare a rebound prefix, default namespace, conflicting binding). All fail onmain.pnpm typecheck && pnpm lint && pnpm format:check && pnpm test, pluspnpm --filter @office-kit/pptx-editor testandpnpm --filter @office-kit/pptx-dev test.Breaking changes
None
Checklist
flagged it above.
comments.
PR represents real work that warrants a maintainer's review, and I am
willing to defend each line in review.
🤖 Generated with Claude Code