From 9f2188ce8ec2f096f5275c376b27153e8153175d Mon Sep 17 00:00:00 2001 From: PathGao Date: Mon, 3 Aug 2026 04:53:42 +0800 Subject: [PATCH] fix(preview): route the preview through the shared sanitize contract #376 introduced `src/lib/utils/sanitize.ts` as the single markdown sanitize policy, and the comment on its `FORBID_TAGS: ['style']` entry argues the preview case specifically: the sanitized HTML is injected into the app's own document, where a document `'; + +const viewerSource = readFileSync('src/lib/MarkdownViewer.svelte', 'utf8'); +const sanitizeSource = readFileSync('src/lib/utils/sanitize.ts', 'utf8'); + +test('the preview sanitizes through the shared policy, not a local config', () => { + assert.match( + viewerSource, + /import \{ sanitizeMarkdownHtml \} from '\.\/utils\/sanitize\.js'/, + 'the viewer must import the shared sanitizer', + ); + assert.match( + viewerSource, + /let sanitizedHtml = \$derived\(sanitizeMarkdownHtml\(htmlContent\)\)/, + 'the preview sink must run the shared sanitizer over tab.content', + ); + + // The regression itself: a DOMPurify call on the document HTML with a + // config assembled at the call site. Whatever that config contains, it is + // by construction not the shared one, and the `