Skip to content

Commit 4868009

Browse files
committed
Make punycode.toASCII not alter ASCII-safe input
This matches `ToASCII` as defined in https://tools.ietf.org/html/rfc3490#section-4.1: > ToASCII never alters a sequence of code points that are all in the ASCII range to begin with (although it could fail). Applying the ToASCII operation multiple times has exactly the same effect as applying it just once. Closes #59.
1 parent e29d10d commit 4868009

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

punycode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const delimiter = '-'; // '\x2D'
1515

1616
/** Regular expressions */
1717
const regexPunycode = /^xn--/;
18-
const regexNonASCII = /[^\x20-\x7E]/; // unprintable ASCII chars + non-ASCII chars
18+
const regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
1919
const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
2020

2121
/** Error messages */

tests/tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ const testData = {
203203
'decoded': '\uD83D\uDCA9.la',
204204
'encoded': 'xn--ls8h.la'
205205
},
206+
{
207+
'description': 'Non-printable ASCII',
208+
'decoded': '\0\x01\x02foo.bar',
209+
'encoded': '\0\x01\x02foo.bar'
210+
},
206211
{
207212
'description': 'Email address',
208213
'decoded': '\u0434\u0436\u0443\u043C\u043B\u0430@\u0434\u0436p\u0443\u043C\u043B\u0430\u0442\u0435\u0441\u0442.b\u0440\u0444a',

0 commit comments

Comments
 (0)