From d2ccaebbe6b9317e03c73f441ca4effece3c4d06 Mon Sep 17 00:00:00 2001 From: DimaIT Date: Tue, 19 Dec 2023 13:07:55 +0100 Subject: [PATCH] fix(tokenizer): treat textarea as special tag --- src/Tokenizer.spec.ts | 25 ++++ src/Tokenizer.ts | 33 ++++- src/__snapshots__/Tokenizer.spec.ts.snap | 175 +++++++++++++++++++++++ 3 files changed, 227 insertions(+), 6 deletions(-) diff --git a/src/Tokenizer.spec.ts b/src/Tokenizer.spec.ts index f2d642c6..51381089 100644 --- a/src/Tokenizer.spec.ts +++ b/src/Tokenizer.spec.ts @@ -33,6 +33,9 @@ describe("Tokenizer", () => { it("for self-closing title tag", () => { expect(tokenize("<div></div>")).toMatchSnapshot(); }); + it("for self-closing textarea tag", () => { + expect(tokenize("<textarea /><div></div>")).toMatchSnapshot(); + }); }); describe("should support standard special tags", () => { @@ -45,6 +48,28 @@ describe("Tokenizer", () => { it("for normal sitle tag", () => { expect(tokenize("<title>
")).toMatchSnapshot(); }); + it("for normal textarea tag", () => { + expect( + tokenize("
"), + ).toMatchSnapshot(); + }); + }); + + describe("should treat html inside special tags as text", () => { + it("for div inside script tag", () => { + expect(tokenize("")).toMatchSnapshot(); + }); + it("for div inside style tag", () => { + expect(tokenize("")).toMatchSnapshot(); + }); + it("for div inside title tag", () => { + expect(tokenize("<div></div>")).toMatchSnapshot(); + }); + it("for div inside textarea tag", () => { + expect( + tokenize(""), + ).toMatchSnapshot(); + }); }); describe("should correctly mark attributes", () => { diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index 423a8574..0ae7fca9 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -69,6 +69,7 @@ const enum State { // Special tags BeforeSpecialS, // Decide if we deal with `