// @vitest-environment jsdom import { describe, expect, it } from "vitest"; import { toHtml } from "./NoteEditor"; describe("toHtml sanitization (M15/THREAT-006)", () => { // Plain text path — escape special chars when no tag-like content present. it("escapes plain text ampersand", () => { expect(toHtml("a & b")).toBe("a & b"); }); it("converts newlines to
in plain text", () => { expect(toHtml("line1\nline2")).toBe("line1
line2"); }); // Strips disallowed tags by replacing with their textContent. it("strips iframe", () => { expect(toHtml('')).not.toContain("iframe"); }); it("strips base", () => { expect(toHtml('')).not.toContain("base"); }); it("strips meta refresh", () => { expect(toHtml('')).not.toContain("meta"); }); it("strips form", () => { expect(toHtml('
')).not.toContain("form"); }); it("strips script", () => { expect(toHtml('')).not.toContain("script"); }); it("strips style", () => { expect(toHtml('')).not.toContain("style"); }); it("strips object/embed", () => { expect(toHtml('')).not.toContain("object"); expect(toHtml('')).not.toContain("embed"); }); it("strips all attributes from allowed tags", () => { const result = toHtml('bold'); expect(result).toContain("bold"); expect(result).not.toContain("onclick"); expect(result).not.toContain("style"); expect(result).not.toContain("id="); }); it("strips href from a tags (a is not in allow-list)", () => { const result = toHtml('click'); expect(result).not.toContain("href"); expect(result).not.toContain(" { expect(toHtml("hi")).toContain("hi"); }); it("preserves italic, underline, strikethrough", () => { expect(toHtml("xyz")).toContain("xyz"); }); it("preserves strong and em", () => { expect(toHtml("xy")).toContain("xy"); }); it("preserves headings h2 and h3", () => { expect(toHtml("

x

y

")).toContain("

x

y

"); }); it("preserves lists", () => { const result = toHtml(""); expect(result).toContain("