fix: do not line-end-normalize a CR character reference in content#41
Merged
Merged
Conversation
XML 1.0 section 2.11 end-of-line normalization applies only to literal line breaks in the input, not to characters produced by a character or entity reference (sections 4.6/4.1). A character reference resolving to a carriage return (`
` or `&rgrove#13;`) in element content was being converted to a line feed because consumeContentReference routed the resolved text through addText's unconditional normalizeLineBreaks call. Add a `normalize` parameter to addText (default true) and pass false from consumeContentReference so resolved references preserve U+000D. The CDATA and CharData callers keep the default, since literal content is subject to section 2.11. The attribute path was already correct (issue rgrove#6).
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.
Problem
A character reference resolving to a carriage return (

or ) in element text content is wrongly converted to a line feed.XML 1.0 section 2.11 end-of-line normalization applies only to literal line breaks in the input, not to characters produced by a character or entity reference (see sections 4.6 / 4.1). The reference must be passed through to the application as the literal character it denotes.
The cause:
consumeContentReferenceroutes the resolved reference text throughaddText, which unconditionally callsnormalizeLineBreaks. So a resolved
is collapsed to\njust like a literal CR in the source would be.Evidence this is the intended behavior
xmltest/valid/sa/067.xml(<doc> </doc>) has canonical output<doc> </doc>, i.e. the CR must survive.Fix
Add a
normalizeparameter toaddText(defaulttrue) gating thenormalizeLineBreakscall, and passfalsefromconsumeContentReference. The CDATA and CharData callers keep the defaulttrue, since literal content is subject to section 2.11.Verification
main('\n' !== '\r') and passes with the fix.References