Skip to content

Commit f6dc2d3

Browse files
authoredMar 22, 2023
fix(tokenizer): Reset baseState after closing tag name (#1460)
Prevents leaking baseState and breaking the Tokenizer if followed by an entity - #1426
1 parent 6da614e commit f6dc2d3

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
 

‎src/Tokenizer.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ describe("Tokenizer", () => {
4747
});
4848
});
4949

50+
describe("should not break after special tag followed by an entity", () => {
51+
it("for normal special tag", () => {
52+
expect(tokenize("<style>a{}</style>&apos;<br/>")).toMatchSnapshot();
53+
});
54+
it("for self-closing special tag", () => {
55+
expect(tokenize("<style />&apos;<br/>")).toMatchSnapshot();
56+
});
57+
});
58+
5059
it("should not lose data when pausing", () => {
5160
const log: unknown[][] = [];
5261
const tokenizer = new Tokenizer(

‎src/Tokenizer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ export default class Tokenizer {
455455
// Skip everything until ">"
456456
if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) {
457457
this.state = State.Text;
458+
this.baseState = State.Text;
458459
this.sectionStart = this.index + 1;
459460
}
460461
}

‎src/__snapshots__/Tokenizer.spec.ts.snap

+70
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,75 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Tokenizer should not break after special tag followed by an entity for normal special tag 1`] = `
4+
[
5+
[
6+
"onopentagname",
7+
1,
8+
6,
9+
],
10+
[
11+
"onopentagend",
12+
6,
13+
],
14+
[
15+
"ontext",
16+
7,
17+
10,
18+
],
19+
[
20+
"onclosetag",
21+
12,
22+
17,
23+
],
24+
[
25+
"ontextentity",
26+
39,
27+
],
28+
[
29+
"onopentagname",
30+
25,
31+
27,
32+
],
33+
[
34+
"onselfclosingtag",
35+
28,
36+
],
37+
[
38+
"onend",
39+
],
40+
]
41+
`;
42+
43+
exports[`Tokenizer should not break after special tag followed by an entity for self-closing special tag 1`] = `
44+
[
45+
[
46+
"onopentagname",
47+
1,
48+
6,
49+
],
50+
[
51+
"onselfclosingtag",
52+
8,
53+
],
54+
[
55+
"ontextentity",
56+
39,
57+
],
58+
[
59+
"onopentagname",
60+
16,
61+
18,
62+
],
63+
[
64+
"onselfclosingtag",
65+
19,
66+
],
67+
[
68+
"onend",
69+
],
70+
]
71+
`;
72+
373
exports[`Tokenizer should not lose data when pausing 1`] = `
474
[
575
[

0 commit comments

Comments
 (0)
Please sign in to comment.