import { describe, it, expect } from "vitest";
import { sanitizePageHtml } from "./pageHtml";
describe("sanitizePageHtml (landing-page rich text allow-list)", () => {
it("keeps the editor's formatting", () => {
const html = '
Hi
b i u s
- y
q
';
expect(sanitizePageHtml(html)).toBe(html.replace("text-align: center", "text-align:center").replace("
", "
"));
});
it("drops scripts, handlers, javascript: links, iframes, images and foreign styles", () => {
const out = sanitizePageHtml(
'a
j' +
'
' +
'p',
);
expect(out).not.toMatch(/script|onclick|onerror|javascript|iframe|
a");
});
it("opens outside links safely and keeps on-site, mail and phone links", () => {
expect(sanitizePageHtml('x')).toBe('x');
expect(sanitizePageHtml('m')).toContain('href="mailto:a@b.c"');
expect(sanitizePageHtml('t')).toContain('href="tel:+60123"');
expect(sanitizePageHtml('s')).toContain('href="/p/INS/x"');
expect(sanitizePageHtml('h')).not.toContain("plain.com");
expect(sanitizePageHtml('j')).toBe('j');
});
});