mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { sanitizeSurrogates } from './sanitizeSurrogates';
|
||
|
||
describe('sanitizeSurrogates', () => {
|
||
it('returns surrogate-free strings unchanged', () => {
|
||
expect(sanitizeSurrogates('')).toBe('');
|
||
expect(sanitizeSurrogates('https://host/sub/uuid#remark')).toBe('https://host/sub/uuid#remark');
|
||
});
|
||
|
||
it('keeps valid surrogate pairs intact', () => {
|
||
expect(sanitizeSurrogates('server 😀 name')).toBe('server 😀 name');
|
||
});
|
||
|
||
it('replaces a lone high surrogate', () => {
|
||
expect(sanitizeSurrogates('abc\uD83D')).toBe('abc<62>');
|
||
expect(sanitizeSurrogates('\uD83Dxyz')).toBe('<27>xyz');
|
||
});
|
||
|
||
it('replaces a lone low surrogate', () => {
|
||
expect(sanitizeSurrogates('abc\uDE00def')).toBe('abc<62>def');
|
||
});
|
||
|
||
it('makes a truncated-emoji string safe for encodeURI', () => {
|
||
const broken = 'remark \uD83D truncated';
|
||
expect(() => encodeURI(broken)).toThrow();
|
||
expect(() => encodeURI(sanitizeSurrogates(broken))).not.toThrow();
|
||
});
|
||
});
|