import { describe, it, expect } from 'vitest' import { sanitizeHtml, DefaultAllowlist } from '../../../src/bootstrap/util/sanitizer' describe('sanitizer', () => { describe('DefaultAllowlist', () => { it('should have a wildcard entry with common attributes', () => { expect(DefaultAllowlist['*']).toBeDefined() const wildcardStrings = DefaultAllowlist['*'].filter((a) => typeof a === 'string') expect(wildcardStrings).toContain('class') expect(wildcardStrings).toContain('id') expect(wildcardStrings).toContain('role') }) it('should allow safe tags', () => { for (const tag of ['a', 'b', 'br', 'div', 'em', 'h1', 'img', 'li', 'ol', 'p', 'span', 'strong', 'ul']) { expect(tag in DefaultAllowlist).toBe(true) } }) it('should allow href/target/title/rel for ', () => { expect(DefaultAllowlist.a).toEqual(expect.arrayContaining(['href', 'target', 'title', 'rel'])) }) }) describe('sanitizeHtml', () => { it('should return empty string for empty input', () => { expect(sanitizeHtml('', DefaultAllowlist)).toBe('') }) it('should use custom sanitize function when provided', () => { const customFn = (html: string) => html.toUpperCase() expect(sanitizeHtml('test', DefaultAllowlist, customFn)).toBe('TEST') }) it('should keep allowed elements', () => { const result = sanitizeHtml('bold', DefaultAllowlist) expect(result).toContain('') expect(result).toContain('bold') }) it('should remove disallowed elements', () => { const result = sanitizeHtml('safe', DefaultAllowlist) expect(result).not.toContain('