Skip to content

xml: handle single-quoted literals, comments, and PIs in DOCTYPE - #143

Open
xgbtxy wants to merge 1 commit into
tdewolff:masterfrom
xgbtxy:fix/xml-doctype-literals-and-comments
Open

xgbtxy wants to merge 1 commit into
tdewolff:masterfrom
xgbtxy:fix/xml-doctype-literals-and-comments

Conversation

@xgbtxy

@xgbtxy xgbtxy commented Dec 2, 2026

Copy link
Copy Markdown

Summary

Fixes xml.Lexer.shiftDOCTYPEText in xml/lex.go for W3C XML 1.0 (Fifth Edition) Sections 2.3, 2.5, 2.6, and 2.8 doctypedecl conformance:

  • Track both single-quoted ('...') and double-quoted ("...") SystemLiteral, PubidLiteral, and EntityValue strings instead of only double quotes. Previously single-quoted literals containing >, [, or " either terminated DOCTYPEToken prematurely or swallowed the rest of the document.
  • Skip XML comments (<!-- ... -->) and processing instructions (<? ... ?>) inside internal subsets ([...]) so ] or quote characters inside them do not prematurely close the internal subset.

Verification

  • Added 7 focused TestTokens cases in xml/lex_test.go (6 failed before the fix, all pass after).
  • Verified gofmt -l xml/lex.go xml/lex_test.go, go vet ./xml/..., and go test -race -count=1 ./... pass across all packages.

Per W3C XML 1.0 (Fifth Edition) Sections 2.3, 2.5, 2.6, and 2.8,
DOCTYPE SystemLiteral, PubidLiteral, and EntityValue strings may be
delimited by either single or double quotes, and internal subsets may
contain comments and processing instructions.

Previously shiftDOCTYPEText only tracked double quotes, causing
single-quoted literals containing '>', '[', or '"' and internal subset
comments or PIs containing ']' to either terminate the DOCTYPE token
prematurely or swallow the remainder of the document.

Signed-off-by: Yan Chen <yan8925298@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 02:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

3 participants