Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/engine/operations/encodings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,13 @@ function decodePunycodeLabel(label: string): string {
if (index >= encoded.length) throw new OperationError('Punycode input ends mid-sequence.');
const char = encoded.charCodeAt(index++);
const digit =
char - 48 < 10 ? char - 22 : char - 65 < 26 ? char - 65 : char - 97 < 26 ? char - 97 : PUNY_BASE;
char >= 48 && char <= 57
? char - 22
: char >= 65 && char <= 90
? char - 65
: char >= 97 && char <= 122
? char - 97
: PUNY_BASE;
if (digit >= PUNY_BASE) throw new OperationError('Punycode contains a non-basic digit.');

i += digit * w;
Expand Down
7 changes: 7 additions & 0 deletions src/engine/tests/operations.verified.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ describe('edge cases the property tests turned up', () => {
expect(await refusal('%%%%%', ['from-base85', { Alphabet: 'Z85' }])).toMatch(/out of range/);
});

it('Punycode refuses punctuation where a digit should be', async () => {
expect(await text('xn--mnchen-3YA', 'from-punycode')).toBe('münchen');
expect(await refusal('xn--mnchen-3y!', 'from-punycode')).toMatch(/non-basic digit/);
expect(await refusal('xn--a:b', 'from-punycode')).toMatch(/non-basic digit/);
expect(await refusal('xn--[]', 'from-punycode')).toMatch(/non-basic digit/);
});

it('Base58 turns each leading 1 into one zero byte, and nothing into nothing', async () => {
expect(await bytesOut('', 'from-base58')).toBe('');
expect(toHex(await bytesOut('1', 'from-base58'))).toBe('00');
Expand Down
Loading