Skip to content

fix(tokenizer): require full --> to close comments in xmlMode#2383

Merged
fb55 merged 2 commits intomasterfrom
fix/xml-comment-end
Mar 19, 2026
Merged

fix(tokenizer): require full --> to close comments in xmlMode#2383
fb55 merged 2 commits intomasterfrom
fix/xml-comment-end

Conversation

@fb55
Copy link
Owner

@fb55 fb55 commented Mar 19, 2026

In HTML, <!--> is a valid empty comment per the spec. However, in XML comments must be closed by -->, so <!--> should be treated as an opening — not a complete comment. Skip the short-comment shortcut when xmlMode is enabled.

Fixes #1823

In HTML, `<!-->` is a valid empty comment per the spec. However, in XML
comments must be closed by `-->`, so `<!-->` should be treated as an
opening — not a complete comment. Skip the short-comment shortcut when
xmlMode is enabled.

Fixes #1823
Copilot AI review requested due to automatic review settings March 19, 2026 07:54
@fb55 fb55 enabled auto-merge (squash) March 19, 2026 07:54
@fb55 fb55 merged commit 21dedfa into master Mar 19, 2026
12 checks passed
@fb55 fb55 deleted the fix/xml-comment-end branch March 19, 2026 07:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts the tokenizer’s comment-closing behavior so that XML mode no longer treats the HTML-only shorthand <!--> as a complete (empty) comment, matching XML’s requirement that comments close with -->. It also adds a regression test covering the reported issue (#1823).

Changes:

  • Skip the <!--> short-comment fast path when xmlMode is enabled.
  • Add a tokenizer snapshot test reproducing the XML-mode misparse from #1823.
  • Update snapshots to reflect the corrected tokenization behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Tokenizer.ts Changes initial comment-end sequence matching to require a real --> close in xmlMode (no <!--> shortcut).
src/Tokenizer.spec.ts Adds a regression test asserting <!--> is not treated as a complete comment in XML mode.
src/__snapshots__/Tokenizer.spec.ts.snap Records expected event stream for the new regression test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

).toMatchSnapshot();
});

it("should not treat <!--> as a complete comment in xmlMode", () => {
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.

latest version xml comment is not ending as expecting

2 participants