mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-10-01 04:21:58 +00:00
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:
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user