fix(xml): preserve declaration state through embedded markup

Merged
TH
2d ago
+79-10

Summary

The declaration scanner skips complete comments and processing instructions inside an unquoted bracketed subset. When their closing delimiter is absent, it continues the base parser’s quote and bracket scan. Each absent delimiter requires at most one search to the end of the document.

Before / after

On the PR base, an apostrophe or literal ]> inside a complete embedded comment or processing instruction could hide the following root or prematurely end the declaration. The parser now skips to the markup’s own closer and returns the root.

Both the base and this head return root for <!DOCTYPE root [<!-- x <a> b]><root/> and its processing-instruction counterpart. Top-level markup keeps its historical delimiter search offset and missing-closer errors.

All four reviewed inputs with a complete comment or PI containing ]> and no external subset closer now raise XML declaration is not closed. The base returned root by ending the declaration inside the embedded markup. Adding an external ]> returns root on this head.

Validation

CI pending at ee56e1c34d113d47aceb79b7c82e0c6a345ac8db. Public-parser cases cover complete and unterminated subset markup, overlapping comment delimiters, and unterminated top-level markup. Validation is CI-only.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.