|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { sanitizeEmailStyleValue } from './emailHtmlPolicy' |
| 3 | + |
| 4 | +describe('sanitizeEmailStyleValue', () => { |
| 5 | + it.each([ |
| 6 | + [' red ', 'red'], |
| 7 | + ['red!important', 'red'], |
| 8 | + [' red \t!IMPORTANT \n', 'red'], |
| 9 | + ['red !important extra', 'red !important extra'], |
| 10 | + ['red ! important', 'red ! important'], |
| 11 | + ['!important', undefined], |
| 12 | + ])('normalizes %j to %j', (value, expected) => { |
| 13 | + expect(sanitizeEmailStyleValue('color', value)).toBe(expected) |
| 14 | + }) |
| 15 | + |
| 16 | + it('rejects oversized values containing long internal whitespace', () => { |
| 17 | + const value = `red${' '.repeat(200_000)}x` |
| 18 | + expect(sanitizeEmailStyleValue('color', value)).toBeUndefined() |
| 19 | + }) |
| 20 | + |
| 21 | + it('applies the length limit after removing the important suffix', () => { |
| 22 | + const value = 'a'.repeat(512) |
| 23 | + expect(sanitizeEmailStyleValue('font-family', `${value} !important`)).toBe( |
| 24 | + value, |
| 25 | + ) |
| 26 | + expect( |
| 27 | + sanitizeEmailStyleValue('font-family', `${value}a !important`), |
| 28 | + ).toBeUndefined() |
| 29 | + }) |
| 30 | +}) |
0 commit comments