import { describe, expect, it } from "vitest"; import { sanitizeHtml } from "@/lib/html"; describe("sanitizeHtml (stored editor bodies)", () => { it("strips

After

'); expect(html).not.toContain(" { const html = sanitizeHtml(''); expect(html).not.toContain("onerror"); expect(html).toContain('src="/uploads/x.png"'); }); it("removes javascript: URLs from links", () => { const html = sanitizeHtml('click me'); expect(html).not.toContain("javascript:"); expect(html).toContain("click me"); }); it("keeps the marks the editor produces, including underline", () => { const html = sanitizeHtml("

under gone bold

"); expect(html).toContain("under"); expect(html).toContain("gone"); expect(html).toContain("bold"); }); it("keeps relative upload URLs and http(s) images", () => { expect(sanitizeHtml('text')).toContain( '/uploads/a.png', ); expect(sanitizeHtml('')).toContain( "https://example.com/b.jpg", ); }); it("keeps table structure", () => { const html = sanitizeHtml( "
h
d
", ); expect(html).toContain(""); expect(html).toContain(""); expect(html).toContain(""); }); it("drops iframes and style tags", () => { const html = sanitizeHtml('

ok

'); expect(html).not.toContain("iframe"); expect(html).not.toContain("
hd