Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Tokenizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ describe("Tokenizer", () => {
).toMatchSnapshot();
});

it("should not treat <!--> as a complete comment in xmlMode", () => {
expect(
tokenize(
"<root><node>start</node><!--><node>should ignore</node><--><node>end</node></root>",
{ xmlMode: true },
),
).toMatchSnapshot();
});

it.each([
"script",
"style",
Expand Down
7 changes: 5 additions & 2 deletions src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,11 @@ export default class Tokenizer {
if (c === CharCodes.Dash) {
this.state = State.InCommentLike;
this.currentSequence = Sequences.CommentEnd;
// Allow short comments (eg. <!-->)
this.sequenceIndex = 2;
/*
* In HTML, `<!-->` is a valid empty comment. In XML, comments
* must be closed by `-->`, so we require the full sequence.
*/
this.sequenceIndex = this.xmlMode ? 0 : 2;
this.sectionStart = this.index + 1;
} else {
this.state = State.InDeclaration;
Expand Down
66 changes: 66 additions & 0 deletions src/__snapshots__/Tokenizer.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,72 @@ exports[`Tokenizer > should not lose data when pausing 1`] = `
]
`;

exports[`Tokenizer > should not treat <!--> as a complete comment in xmlMode 1`] = `
[
[
"onopentagname",
1,
5,
],
[
"onopentagend",
5,
],
[
"onopentagname",
7,
11,
],
[
"onopentagend",
11,
],
[
"ontext",
12,
17,
],
[
"onclosetag",
19,
23,
],
[
"oncomment",
28,
58,
2,
],
[
"onopentagname",
60,
64,
],
[
"onopentagend",
64,
],
[
"ontext",
65,
68,
],
[
"onclosetag",
70,
74,
],
[
"onclosetag",
77,
81,
],
[
"onend",
],
]
`;

exports[`Tokenizer > should support self-closing special tags > for self-closing script tag 1`] = `
[
[
Expand Down
Loading