BREAKING(xml): expose doctype and processing instructions from parse - #7261
Open
tomas-zijdemans wants to merge 3 commits into
Open
BREAKING(xml): expose doctype and processing instructions from parse#7261tomas-zijdemans wants to merge 3 commits into
tomas-zijdemans wants to merge 3 commits into
Conversation
The sync parser walked the whole DOCTYPE declaration but stored nothing. Capture the name and PUBLIC/SYSTEM identifiers into a new XmlDoctype type exposed as XmlDocument.doctype (only reachable with disallowDoctype: false), and teach stringify to emit it behind a new doctype option (default true). Breaking: a DOCTYPE after the root element or a second DOCTYPE now throws (XML 1.0 §2.8); both were silently accepted before, which becomes observable now that the doctype is stored. The DTD internal subset is deliberately not captured and is dropped on round-trip. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The sync parser validated processing instructions and then discarded them, even though XML 1.0 §2.6 requires PIs to be passed through to the application. Comments outside the root element were silently dropped the same way. Add XmlProcessingInstructionNode to the XmlNode union, collect PIs and comments outside the root into new prolog/epilog fields on XmlDocument (omitted when empty), and teach stringify to emit all of it. Move the ignoreProcessingInstructions option from ParseStreamOptions to BaseParseOptions so the sync parser accepts it too; streaming behavior is unchanged. Add the isProcessingInstruction type guard. Breaking: exhaustive switches over XmlNode gain a case, and PIs now appear in children by default for documents that contain them. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7261 +/- ##
========================================
Coverage 95.03% 95.03%
========================================
Files 618 618
Lines 51596 51954 +358
Branches 9340 9434 +94
========================================
+ Hits 49035 49376 +341
- Misses 2021 2032 +11
- Partials 540 546 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
parse()validated processing instructions and the DOCTYPE, then threw both away. This PR keeps them: the doctype lands onXmlDocument.doctype, and PIs become tree nodes. This addresses the gap noted at the end of #7212.XML 1.0 §2.6 is blunt about PIs: they "MUST be passed through to the application". Comments outside the root element were dropped the same way, so a license header above
<root>vanished on round-trip. Also fixed.What changed
Breaking changes
Fidelity notes
<!DOCTYPE>re-serializes after it. Still valid per §2.8.<!DOCTYPE foo PUBLIC "pub">(public id, no system id) is leniently parsed and re-serialized as-is, matching the DOM XMLSerializer.Testing
46 new tests across parser, serializer, and type guards, including round-trips: XHTML doctype, xml-stylesheet PI, internal-subset drop. One existing test asserted the old discarding behavior and was rewritten. deno task ok passes.
The two commits split cleanly: doctype first, PIs second, in case one half needs to land alone.
Built with assistance from Claude Code