Repository navigation
Fix NBSP-only text being dropped and entities being decoded twice - #233
Merged
leonelsanchesdasilva merged 1 commit intoNov 8, 2026
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leonelsanchesdasilva
approved these changes
Nov 8, 2026
leonelsanchesdasilva
left a comment
Collaborator
There was a problem hiding this comment.
Thank you!
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
Two bugs make the output of a transform differ from a spec-compliant processor such as Saxon:
U+00A0) is dropped from the output.&#37;,&#x41;,&lt;and&gt;are decoded twice.These matter for Mexico's SAT CFDI invoices. Their "cadena original" is produced by XSLT and verified byte for byte against a digital signature, so either bug makes a valid invoice fail verification. This follows DesignLiquido/xpath#2, which fixed
normalize-space()for NBSP.<r a=" "/>withvalue-of select="r/@a"U+00A0<t>17&#37;</t>17%17%<t>&lt;x&gt;</t><x><x>Root causes
NBSP-only text.
xmlTransformedTextRecursiveandxmlProducesNoOutputskip blank text nodes usingnodeValue.trim() !== ''. JavaScript'strim()stripsU+00A0, but XML whitespace is only#x9,#xA,#xDand#x20.Double decoding has two separate causes:
htmlEntityDecoderuns separate passes for named, decimal and hex references.&#37;becomes%in the first pass and%in the next.xmlTransformedTextRecursivecallsxmlUnescapeTexton unescaped output, converting a literal<that the parser had already decoded from&lt;.Changes
src/dom/xml-functions.ts: addisXmlWhitespaceOnlyand use it for both blank-text checks.src/dom/html-entity-decoder.ts: decode all references in one regex pass, so output is never re-read as input.src/dom/xml-functions.ts: stop unescaping text nodes on output, and removexmlUnescapeText, which is no longer used.Whitespace-only text is still skipped, and real references such as
%,<and&still decode normally.Behaviour change to review:
xmlUnescapeTextwas exported fromsrc/dom/xml-functions.ts. It has no other callers insrcortests, but tell me if you consider it public API and I'll keep it. Any caller relying on the extra decode will now get the correct literal text.Testing
tests/entities-and-nbsp-output.test.tsx. 8 of its 15 cases fail without the source changes; the other 7 guard existing behaviour.Known related issue, not changed here
xmlEscapeTextcollapses&amp;back to&, so a literal&value isn't re-escaped correctly on XML output. It looked like a separate change, so I left it out; happy to follow up.Drafted with Claude's assistance (investigation, patch and tests); verified as described above.
🤖 Generated with Claude Code