feat(headerspec): add UTF-8 encoding/decoding support

* Implement round-trip encoding/decoding for UTF-8 values in header functions.
* Update encodeHeaderValue and decodeHeaderValue to use base64 utility functions.
* Add tests for UTF-8 header value handling.
* Update Vite config to externalize base64 utility.
This commit is contained in:
2026-09-23 20:57:50 +02:00
parent b587cbd3c4
commit 7f8982fa35
10 changed files with 1753 additions and 2160 deletions
@@ -126,11 +126,22 @@ describe('encodeHeaderValue / decodeHeaderValue', () => {
expect(decoded).toBe(original);
});
it('should round-trip UTF-8 values', () => {
const original = 'café ☕ 你好';
expect(decodeHeaderValue(encodeHeaderValue(original))).toBe(original);
});
it('should decode __ prefixed values', () => {
const encoded = '__' + btoa('hello');
expect(decodeHeaderValue(encoded)).toBe('hello');
});
it('should decode UTF-8 values with the __ prefix', () => {
const bytes = new TextEncoder().encode('café ☕');
const binary = Array.from(bytes, (byte) => String.fromCharCode(byte)).join('');
expect(decodeHeaderValue('__' + btoa(binary))).toBe('café ☕');
});
it('should return plain values as-is', () => {
expect(decodeHeaderValue('plain')).toBe('plain');
});