Skip to content

Require whitespace before standalone in the XML declaration - #53

Closed
kripod wants to merge 1 commit into
rgrove:mainfrom
kripod:fix/xml-declaration-standalone-whitespace
Closed

kripod wants to merge 1 commit into
rgrove:mainfrom
kripod:fix/xml-declaration-standalone-whitespace

Conversation

@kripod

@kripod kripod commented Nov 11, 2026

Copy link
Copy Markdown

An XML declaration with no whitespace between the encoding and standalone is currently accepted:

parseXml('<?xml version="1.0" encoding="UTF-8"standalone="yes"?><a/>')
// parses, but should throw

SDDecl starts with a mandatory S, i.e. whitespace (production 32), the same way EncodingDecl does. The whitespace before encoding is already enforced (version="1.0"encoding=… throws). The one before standalone isn’t checked when an encoding precedes it.

This change only looks for standalone if whitespace was consumed after the encoding. It adds one regression test, and coverage stays at 100%.

I left the changelog untouched, as the previous fixes did. Happy to add an entry if preferred.

🤖 Generated with Claude Code

An XML declaration with no whitespace between the encoding declaration
and the standalone declaration was accepted, e.g.:

    <?xml version="1.0" encoding="UTF-8"standalone="yes"?>

`SDDecl` starts with a mandatory `S`, just as `EncodingDecl` does. The
whitespace before `encoding` was already required. The whitespace before
`standalone` is now required as well when an encoding precedes it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@rgrove

rgrove commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks for bringing this issue to my attention!

While the fix here does address the narrow case you described, I realized while reviewing this that a more comprehensive fix was needed to cover additional cases, and that there was a similar issue related to missing whitespace before a doctype's system identifier. Because of that, I decided to treat this PR as a bug report and implemented the fix using a slightly different approach, which you can see in bdfa328.

@rgrove rgrove closed this Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants