Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/sanitize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ describe("stripHtml", () => {
expect(stripHtml("<script>alert(1)</script>")).toBe("alert(1)");
expect(stripHtml("<b>Hello</b>")).toBe("Hello");
});
it("returns plain text unchanged", () => {
expect(stripHtml("Hello World")).toBe("Hello World");
});

it("decodes apostrophe entities", () => {
expect(stripHtml("it's fine")).toBe("it's fine");
expect(stripHtml("it's fine")).toBe("it's fine");
});

it("handles mixed tags and entities", () => {
expect(stripHtml("<b>Tom &amp; Jerry</b>")).toBe("Tom & Jerry");
});
});

describe("validateTextInput", () => {
Expand Down Expand Up @@ -101,4 +113,10 @@ describe("validateTextInput", () => {
error: "Name must be 5 characters or fewer",
});
});
it("strips script injection and returns ok", () => {
expect(validateTextInput("<script>alert(1)</script>Hello", "Name")).toEqual({
ok: true,
value: "Hello",
});
});
});
Loading