Repository navigation
fix(parser): decode numeric character references instead of re-escaping them - #14
Merged
Merged
Conversation
…ng them A `•` / `–` anywhere in a part (a numbering `w:lvlText`, a run's text) survived parsing as literal text, so the builder escaped its `&` on the next save and Word rendered the reference itself. Parse with `htmlEntities` so references decode once; escape on the build side in the value processors, writing attribute tab/LF/CR back as references so a decoded alt-text line break isn't normalized to a space. The SVG sanitizer now strips tab/CR/LF before classifying a URL scheme, as browsers do. Fixes #12 Triage-Routine: true Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012GoxD36rnNfg6uArkVxtJL
Owner
Author
|
🤖 docx-cli triage Opened this for #12: numeric character references ( Action needed: approve/merge — review the diff and the two decision checkboxes in the description, then merge #14. Generated by Claude Code |
… literal
`htmlEntities: {}` turns on numeric character-reference decoding with an
empty named-entity table, so ` `/`©` (undefined in XML) stay
literal instead of being silently rewritten. Per maintainer decision on #14.
Triage-Routine: true
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012GoxD36rnNfg6uArkVxtJL
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.
🤖 docx-cli triage
What was wrong
Numeric character references were never decoded on parse, so any save re-escaped their
&.docx replace refs.docx Alpha Betaturned<w:lvlText w:val="•"/>intow:val="&#8226;"and• – doneinto&#8226; &#x2013; done, so Word showed the reference text instead of•.readalso showed\•.What changed
XmlNodeparse sets fast-xml-parser'shtmlEntities: {}, which decodes numeric references once (&#8226;still reads as the literal text•). The empty named-entity table means HTML-only names like , which XML doesn't define, stay literal instead of being silently rewritten. The object form is implemented but typedboolean, hence a narrow cast; a test fails if an upgrade drops it.	/ / , so a decoded alt-text line break (descr="a
b") isn't normalized to a space on the next read. Text escaping produces the same bytes as before.isAllowedUrlnow strips tab/CR/LF before checking the scheme, the way browsers do. Without this,java	script:would get past it now that attribute tabs are kept as references.numbering.xmllvlTextsurvive areplace), and an SVG sanitizer regression test.Verification
read→\• \– done, and the saved XML had&#8226;. After:read→• – done, the saved files have<w:lvlText w:val="•"/>and• – done, and there's no&#.bun run test:unit✅ (1713 tests). The pre-commit hook passed on the latest commit.java<TAB>script:bypass that change opened, and replaced a NUL-marker escaping trick with plain value-processor escaping. Both fixed.Decisions (settled)
htmlEntities: {}). in text). A scan of all 36 repo .docx files (493 parts) found zero instances of either. The case this PR does handle, Word's default alt textdescr="…

Description automatically generated", appears 31 times.Fixes #12
🤖 Generated with Claude Code
https://claude.ai/code/session_012GoxD36rnNfg6uArkVxtJL
Generated by Claude Code