Repository navigation
Percent-encode and decode PartName in [Content_Types].xml - #4
Merged
Merged
Conversation
Part names in <Override PartName="..."> are URIs, but the code treated them
inconsistently:
- Renaming a part wrote the raw name ("/ppt/slides/my slide.xml"), which is
not a valid part-name URI and can make Office report the file as corrupt.
Relationship targets were already encoded in the same function.
- parseContentTypes() only stripped the leading slash, so a correctly
encoded override ("/xl/embeddings/Dokument%20Word.docx") never matched the
real part name. contentTypeOf() returned undefined and the package check
reported a false "no-content-type" and "override-missing".
parseContentTypes() now percent-decodes PartName (malformed % sequences fall
back to the raw string), and renaming writes the encoded name. The override
rewrite moves into a small core helper, renameOverride(), so it can be unit
tested; it decodes when looking up the existing override, so encoded entries
are found and updated on rename.
ensureContentType() only writes <Default Extension>, never a PartName, so it
needed no change.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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
Part names in
<Override PartName="…">are URIs and must be percent-encoded (/word/media/my%20logo.png), but the code treated them inconsistently.Write side.
renamePart()wrote'/' + nextunencoded, so renamingppt/slides/slide1.xmltoppt/slides/my slide.xmlproducedPartName="/ppt/slides/my slide.xml", which is not a valid part-name URI and can make Office report the file as corrupt. The relationshipTargetin the same function was already encoded withencodePartUri.Read side.
parseContentTypes()only stripped the leading slash. A correctly encoded override such as/xl/embeddings/Dokument%20Word.docxnever matched the real part namexl/embeddings/Dokument Word.docx, socontentTypeOf()returnedundefinedand the package check reported a false "No content type is defined" warning plus a falseoverride-missing.Changes
parseContentTypes()now percent-decodesPartNamethrough the existingsafeDecode. Malformed%sequences fall back to the raw string and never throw.'/' + encodePartUri(next).renamePart()also looked up the override by comparing the rawPartNameto the decoded part name, so it could not find an encoded override and would have left a stale entry behind. The lookup now decodes the same way.actions.tsinto a small core helper,renameOverride(doc, from, to)insrc/core/package/opc.ts.tests/only coverssrc/core, so this is what makes the write path unit-testable. It is also where CLAUDE.md says the logic belongs.actions.tsshrinks by about 10 lines.ensureContentType()needed no change: it only writes<Default Extension="…">, never aPartName.Reviewer notes
tests/package.test.ts(content type part names): encoded read-side match, exact encoded output on rename, a round trip with a space,%and non-ASCII in one name, an unencodedPartNamewritten by another tool, a splice that leaves the rest of the source byte-identical, malformed%sequences (100%,%E0%A4%A,%zz), andvalidatePackageon a real XLSX with an encoded override.npm run typecheck,npm test(116 tests) andnpm run buildpass.feature/odf-support).Default Extensionvalues are still neither encoded nor decoded. That is outside what this PR set out to fix.🤖 Generated with Claude Code