import { describe, expect, it } from 'vitest'; import { formatLegacyLogHtml } from '../src/logging/formatLegacyLogHtml.js'; describe('formatLegacyLogHtml', () => { it('converts legacy colors and preserves intentional emphasis and line breaks', () => { expect(formatLegacyLogHtml('위험
작게<1>작게만')).toBe( '위험
작게작게만' ); expect(formatLegacyLogHtml('색상', { colorize: false })).toBe('색상'); }); it('escapes executable and unknown markup instead of passing it to v-html', () => { const dirty = [ '', '', 'SVG', '이름', '링크', ].join(''); const clean = formatLegacyLogHtml(dirty); expect(clean).toContain('<script>globalThis.__logXss=1</script>'); expect(clean).toContain('<img src=x onerror="globalThis.__logXss=2">'); expect(clean).toContain('<span class="name" onclick="alert(2)">이름'); expect(clean).not.toMatch(/ { const source = '
장수' + '강조' + "실패주의
"; expect(formatLegacyLogHtml(source)).toBe( '
장수' + '강조' + '실패주의
' ); expect(formatLegacyLogHtml('미허용')).toBe( '<span class="unknown">미허용' ); expect(formatLegacyLogHtml('(전투시드: fixed-seed)')).toBe( '(전투시드: fixed-seed)' ); }); it('keeps the fixed hex color form emitted by flag-change logs but rejects other inline CSS', () => { expect(formatLegacyLogHtml("국기")).toBe( '국기' ); expect(formatLegacyLogHtml("오염")).toBe( "<span style='color:red;background:url(javascript:x)'>오염" ); }); it('escapes dynamic text and incomplete tags', () => { expect(formatLegacyLogHtml('A&B