fix(xml): keep a part whose text carries a bare ampersand - #158
Open
vaibhavdabas16 wants to merge 1 commit into
Open
fix(xml): keep a part whose text carries a bare ampersand#158vaibhavdabas16 wants to merge 1 commit into
vaibhavdabas16 wants to merge 1 commit into
Conversation
An `&` that starts no reference is not well-formed XML, but real XHTML
carries it constantly ("Tom & Jerry", "R&D", "50% & rising"). quick-xml
scans forward for the missing `;` to end of input and then fails the
read, so the whole part was rejected over one character.
For EPUB that loss was silent: chapters load through
`optional_xml_part`, so an unparseable title page was logged and
skipped, and the book appeared to begin at the next chapter (firecrawl#127). The
same stray ampersand fails a required part outright in the OOXML and
ODF paths.
Enable quick-xml's `allow_dangling_amp`, alongside the `check_end_names`
leniency already set here. A dangling ampersand stays literal text;
well-formed references still arrive as `GeneralRef` and resolve as
before.
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.
Fixes #127.
What happens
An
&that begins no reference is not well-formed XML, but real XHTML carries it constantly —Tom & Jerry,R&D,50% & rising. quick-xml scans forward for the missing;, runs to end of input, and fails the read, so one stray character rejects the whole part.In EPUB the loss is silent. Chapters load through
optional_xml_part, which logs and skips a part that will not parse, so a title page containing an ampersand disappears and the book appears to begin at the next chapter — exactly the report in #127. The reporter guessed at the punctuation; the character that actually does it is&.The same stray ampersand fails a required part outright in the OOXML and ODF paths, so this is not EPUB-only.
Repro
Before:
chapter oneAfter:
Tom & Jerry (1940)chapter oneThe change
One line: enable quick-xml's
allow_dangling_amp, next to thecheck_end_namesleniency already set inparse_xml. A dangling ampersand stays literal text; well-formed references still arrive asGeneralRefand resolve throughresolve_entityunchanged.This fits what the parser already does — it recovers from mismatched and unclosed end tags rather than discarding the document — and what
resolve_entityalready does with an unknown entity name, which is to leave it as literal text.Tests
dangling_ampersand_stays_literal_text— four shapes, including a trailing&at end of input, each keeping the content that follows.well_formed_references_still_resolve_beside_a_dangling_one—&,Aand still expand with a bare&in the same run.a_title_page_with_a_bare_ampersand_is_still_read— the EPUB conversion missing title page #127 symptom at the EPUB level.All three fail on
mainand pass here. Full suite green (299 tests, no snapshot changes),cargo fmt --checkandcargo clippy --workspace --all-targets --all-features -D warningsclean.Note, not addressed here
A raw
<in text (<h1>a < b</h1>) still truncates the rest of the element — quick-xml reads it as the start of a tag. Telling a stray<from a real one is a different and much less contained problem, so I left it out rather than widen this change. Happy to open a separate issue if that is worth tracking.Summary by cubic
Fixes #127 by preserving XML/XHTML parts containing a bare
&instead of rejecting the entire part. The ampersand remains literal text, so EPUB title pages are not skipped, while valid entity references continue to resolve normally.Written for commit ca9fdc8. Summary will update on new commits.