diff --git a/craft/src/components/basic/HtmlBlock.toHtml.test.ts b/craft/src/components/basic/HtmlBlock.toHtml.test.ts new file mode 100644 index 0000000..d209ad5 --- /dev/null +++ b/craft/src/components/basic/HtmlBlock.toHtml.test.ts @@ -0,0 +1,13 @@ +import { describe, test, expect } from 'vitest'; +import { HtmlBlock } from './HtmlBlock'; + +const toHtml = (HtmlBlock as any).toHtml; + +describe('HtmlBlock.toHtml sanitizes raw code (A4.1)', () => { + test('strips

hi

' }, ''); + expect(html).not.toContain('hi

'); + }); +}); diff --git a/craft/src/components/basic/HtmlBlock.tsx b/craft/src/components/basic/HtmlBlock.tsx index b0fd034..a5b05df 100644 --- a/craft/src/components/basic/HtmlBlock.tsx +++ b/craft/src/components/basic/HtmlBlock.tsx @@ -140,6 +140,7 @@ HtmlBlock.craft = { /* ---------- HTML export ---------- */ (HtmlBlock as any).toHtml = (props: HtmlBlockProps, _childrenHtml: string) => { - // Output the raw code as-is - return { html: props.code || '' }; + // Run through the same DOMPurify config used for the live editor preview + // so exported pages can't carry `; } return { html: ` -
+ ${items}
${lightboxHtml} `,