Skip to content

Commit

Permalink
Make punycode.toASCII not alter ASCII-safe input
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mathiasbynens committed Jan 6, 2017
1 parent e29d10d commit 4868009
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion punycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const delimiter = '-'; // '\x2D'

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

/** Error messages */
Expand Down
5 changes: 5 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ const testData = {
'decoded': '\uD83D\uDCA9.la',
'encoded': 'xn--ls8h.la'
},
{
'description': 'Non-printable ASCII',
'decoded': '\0\x01\x02foo.bar',
'encoded': '\0\x01\x02foo.bar'
},
{
'description': 'Email address',
'decoded': '\u0434\u0436\u0443\u043C\u043B\u0430@\u0434\u0436p\u0443\u043C\u043B\u0430\u0442\u0435\u0441\u0442.b\u0440\u0444a',
Expand Down

0 comments on commit 4868009

Please sign in to comment.