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

'); }); test('does not wrap output in an unsanitized element carrying the style prop raw', () => { // toHtml only ever returns the sanitized `code` blob -- there is no // wrapper
in the exported HTML, so a malicious // `style` prop (e.g. an attacker-controlled object with a breakout // toString()) has nothing to splice into. const malicious = { toString: () => 'color:red" onmouseover="alert(1)' } as any; const { html } = toHtml({ code: '

hi

', style: malicious }, ''); expect(html).not.toMatch(/onmouseover/); expect(html).not.toMatch(/
hi

'); }); });