Skip to content

Commit

Permalink
fix(tokenizer): Reset baseState after closing tag name (#1460)
Browse files Browse the repository at this point in the history
Prevents leaking baseState and breaking the Tokenizer
if followed by an entity - #1426
  • Loading branch information
KillyMXI committed Mar 22, 2023
1 parent 6da614e commit f6dc2d3
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Tokenizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ describe("Tokenizer", () => {
});
});

describe("should not break after special tag followed by an entity", () => {
it("for normal special tag", () => {
expect(tokenize("<style>a{}</style>&apos;<br/>")).toMatchSnapshot();
});
it("for self-closing special tag", () => {
expect(tokenize("<style />&apos;<br/>")).toMatchSnapshot();
});
});

it("should not lose data when pausing", () => {
const log: unknown[][] = [];
const tokenizer = new Tokenizer(
Expand Down
1 change: 1 addition & 0 deletions src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ export default class Tokenizer {
// Skip everything until ">"
if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) {
this.state = State.Text;
this.baseState = State.Text;
this.sectionStart = this.index + 1;
}
}
Expand Down
70 changes: 70 additions & 0 deletions src/__snapshots__/Tokenizer.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,75 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Tokenizer should not break after special tag followed by an entity for normal special tag 1`] = `
[
[
"onopentagname",
1,
6,
],
[
"onopentagend",
6,
],
[
"ontext",
7,
10,
],
[
"onclosetag",
12,
17,
],
[
"ontextentity",
39,
],
[
"onopentagname",
25,
27,
],
[
"onselfclosingtag",
28,
],
[
"onend",
],
]
`;

exports[`Tokenizer should not break after special tag followed by an entity for self-closing special tag 1`] = `
[
[
"onopentagname",
1,
6,
],
[
"onselfclosingtag",
8,
],
[
"ontextentity",
39,
],
[
"onopentagname",
16,
18,
],
[
"onselfclosingtag",
19,
],
[
"onend",
],
]
`;

exports[`Tokenizer should not lose data when pausing 1`] = `
[
[
Expand Down

0 comments on commit f6dc2d3

Please sign in to comment.