import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { getSanitizedHTML } from "./getSanitizedHTML.ts"; describe("getSanitizedHTML", () => { it("removes executable markup while preserving safe formatting", () => { const result = getSanitizedHTML('Safe'); assert.match(result, /Safe<\/b>/); assert.doesNotMatch(result, /onerror|`; const result = getSanitizedHTML(payload); // 1. Structural tags are kept assert.match(result, //); assert.match(result, /Modal<\/h1>/); assert.match(result, /Close<\/button>/); // 2. Dangerous script bindings and content execution vectors are dropped assert.doesNotMatch(result, /onclick/); assert.doesNotMatch(result, /`; const result = getSanitizedHTML(input); assert.doesNotMatch(result, /foreignObject/i); assert.doesNotMatch(result, /`; const result = getSanitizedHTML(input); // Template and slot kept assert.match(result, //); assert.match(result, //); // Paragraph preserved assert.match(result, /Text<\/p>/); // Dangerous onerror removed, script removed assert.doesNotMatch(result, /onerror/); assert.doesNotMatch(result, /
Text<\/p>/); // Dangerous onerror removed, script removed assert.doesNotMatch(result, /onerror/); assert.doesNotMatch(result, /