From 04c411c9588a30750d9a3b4480ac2efa16f3688f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= <188768+fb55@users.noreply.github.com> Date: Mon, 23 Aug 2021 12:35:27 +0100 Subject: [PATCH] fix(parser): Index of closing tag was misaligned (#913) Reported by @thewilkybarkid in https://github.com/posthtml/posthtml-parser/pull/80#issuecomment-903320512 --- src/Parser.spec.ts | 14 ++++++++++++-- src/Parser.ts | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Parser.spec.ts b/src/Parser.spec.ts index 02e12b15c..b420b005e 100644 --- a/src/Parser.spec.ts +++ b/src/Parser.spec.ts @@ -89,10 +89,20 @@ describe("API", () => { expect(p.startIndex).toBe(0); expect(p.endIndex).toBe(2); - p.write(""); + p.write(""); + + expect(p.startIndex).toBe(11); + expect(p.endIndex).toBe(18); + + p.parseChunk(""); + + expect(p.startIndex).toBe(19); + expect(p.endIndex).toBe(27); }); test("should not have the start index be greater than the end index", () => { diff --git a/src/Parser.ts b/src/Parser.ts index 73f9c2f8d..aae4cc17e 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -286,7 +286,7 @@ export class Parser { } onclosetag(name: string): void { - this.updatePosition(1); + this.updatePosition(2); if (this.lowerCaseTagNames) { name = name.toLowerCase(); }