/** * Sanitizer Utilities Unit Tests * * Tests for HTML/text sanitization functions in lib/sanitizer */ import { describe, it, expect } from 'vitest'; import { sanitizeHtml, sanitizeText, sanitizeUrl, sanitizeYouTubeUrl, } from '@/lib/sanitizer'; // ============================================================================ // sanitizeHtml Tests // ============================================================================ describe('sanitizeHtml', () => { it('should return empty string for null/undefined input', () => { expect(sanitizeHtml(null as any)).toBe(''); expect(sanitizeHtml(undefined as any)).toBe(''); expect(sanitizeHtml('')).toBe(''); }); it('should return clean HTML unchanged', () => { const input = '
This is a clean paragraph.
'; expect(sanitizeHtml(input)).toBe(input); }); it('should remove script tags', () => { const input = 'Safe
Safe
'; const expected = 'Safe
Safe
'; expect(sanitizeHtml(input)).toBe(expected); }); it('should remove script tags with attributes', () => { const input = ''; expect(sanitizeHtml(input)).toBe(''); }); it('should remove javascript: protocol in href', () => { const input = 'Click me'; const result = sanitizeHtml(input); // Should replace javascript: with empty string expect(result).not.toContain('javascript:'); expect(result).toContain(' { const input = '