Skip to content

Commit

Permalink
fix: return early when '<' character found in tag name
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnorris committed Nov 30, 2020
1 parent e8693e7 commit 9a4e2e8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/coverage/
/dist/
/node_modules/
2 changes: 2 additions & 0 deletions src/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export class InTagNameState implements State {

if (character == TAG_START) {
this.nameBuffer += ENCODED_TAG_START;

return "";
}

if (character == TAG_END) {
Expand Down
15 changes: 15 additions & 0 deletions tests/states.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,21 @@ describe("InTagNameState", () => {
expect(got).toEqual(want);
expect(endState).toBeInstanceOf(InCommentState);
});

it("should encode '<' characters within the tag name", () => {
const start = new InTagNameState({
...OptionsWithEncodingEnabled,
allowedTags: new Set(["&lt;&lt;&lt;"]),
});

const text = "<<<>";
const want = `<&lt;&lt;&lt;>`;

const [got, endState] = consumeStringUntilTransitionOrEOF(start, text);

expect(got).toEqual(want);
expect(endState).toBeInstanceOf(InPlaintextState);
});
});

describe("InTagState", () => {
Expand Down

0 comments on commit 9a4e2e8

Please sign in to comment.