Skip to content

Commit

Permalink
fix(parser): Don't override position for implied opening tags (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Aug 23, 2021
1 parent da67eba commit fac221d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ describe("API", () => {
expect(p.endIndex).toBe(12);
});

test("should have the correct position for implied opening tags", () => {
const p = new Parser();

p.write("</p>");

expect(p.startIndex).toBe(0);
expect(p.endIndex).toBe(3);
});

test("should parse <__proto__> (#387)", () => {
const p = new Parser(null);

Expand Down
9 changes: 7 additions & 2 deletions src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ export class Parser {
if (this.lowerCaseTagNames) {
name = name.toLowerCase();
}

this.emitOpenTag(name);
}

private emitOpenTag(name: string) {
this.tagname = name;

const impliesClose =
Expand Down Expand Up @@ -307,11 +312,11 @@ export class Parser {
}
} else this.stack.length = pos;
} else if (name === "p" && !this.options.xmlMode) {
this.onopentagname(name);
this.emitOpenTag(name);
this.closeCurrentTag();
}
} else if (!this.options.xmlMode && (name === "br" || name === "p")) {
this.onopentagname(name);
this.emitOpenTag(name);
this.closeCurrentTag();
}
}
Expand Down

0 comments on commit fac221d

Please sign in to comment.