|
1 | | -/*! http://mths.be/punycode v1.2.3 by @mathias */ |
| 1 | +/*! https://mths.be/punycode v1.3.2 by @mathias */ |
2 | 2 | ;(function(root) { |
3 | 3 |
|
4 | 4 | /** Detect free variables */ |
5 | | - var freeExports = typeof exports == 'object' && exports; |
| 5 | + var freeExports = typeof exports == 'object' && exports && |
| 6 | + !exports.nodeType && exports; |
6 | 7 | var freeModule = typeof module == 'object' && module && |
7 | | - module.exports == freeExports && module; |
| 8 | + !module.nodeType && module; |
8 | 9 | var freeGlobal = typeof global == 'object' && global; |
9 | | - if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { |
| 10 | + if ( |
| 11 | + freeGlobal.global === freeGlobal || |
| 12 | + freeGlobal.window === freeGlobal || |
| 13 | + freeGlobal.self === freeGlobal |
| 14 | + ) { |
10 | 15 | root = freeGlobal; |
11 | 16 | } |
12 | 17 |
|
|
32 | 37 |
|
33 | 38 | /** Regular expressions */ |
34 | 39 | regexPunycode = /^xn--/, |
35 | | - regexNonASCII = /[^ -~]/, // unprintable ASCII chars + non-ASCII chars |
36 | | - regexSeparators = /\x2E|\u3002|\uFF0E|\uFF61/g, // RFC 3490 separators |
| 40 | + regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars |
| 41 | + regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators |
37 | 42 |
|
38 | 43 | /** Error messages */ |
39 | 44 | errors = { |
|
72 | 77 | */ |
73 | 78 | function map(array, fn) { |
74 | 79 | var length = array.length; |
| 80 | + var result = []; |
75 | 81 | while (length--) { |
76 | | - array[length] = fn(array[length]); |
| 82 | + result[length] = fn(array[length]); |
77 | 83 | } |
78 | | - return array; |
| 84 | + return result; |
79 | 85 | } |
80 | 86 |
|
81 | 87 | /** |
82 | | - * A simple `Array#map`-like wrapper to work with domain name strings. |
| 88 | + * A simple `Array#map`-like wrapper to work with domain name strings or email |
| 89 | + * addresses. |
83 | 90 | * @private |
84 | | - * @param {String} domain The domain name. |
| 91 | + * @param {String} domain The domain name or email address. |
85 | 92 | * @param {Function} callback The function that gets called for every |
86 | 93 | * character. |
87 | 94 | * @returns {Array} A new string of characters returned by the callback |
88 | 95 | * function. |
89 | 96 | */ |
90 | 97 | function mapDomain(string, fn) { |
91 | | - return map(string.split(regexSeparators), fn).join('.'); |
| 98 | + var parts = string.split('@'); |
| 99 | + var result = ''; |
| 100 | + if (parts.length > 1) { |
| 101 | + // In email addresses, only the domain name should be punycoded. Leave |
| 102 | + // the local part (i.e. everything up to `@`) intact. |
| 103 | + result = parts[0] + '@'; |
| 104 | + string = parts[1]; |
| 105 | + } |
| 106 | + // Avoid `split(regex)` for IE8 compatibility. See #17. |
| 107 | + string = string.replace(regexSeparators, '\x2E'); |
| 108 | + var labels = string.split('.'); |
| 109 | + var encoded = map(labels, fn).join('.'); |
| 110 | + return result + encoded; |
92 | 111 | } |
93 | 112 |
|
94 | 113 | /** |
|
98 | 117 | * UCS-2 exposes as separate characters) into a single code point, |
99 | 118 | * matching UTF-16. |
100 | 119 | * @see `punycode.ucs2.encode` |
101 | | - * @see <http://mathiasbynens.be/notes/javascript-encoding> |
| 120 | + * @see <https://mathiasbynens.be/notes/javascript-encoding> |
102 | 121 | * @memberOf punycode.ucs2 |
103 | 122 | * @name decode |
104 | 123 | * @param {String} string The Unicode input string (UCS-2). |
|
192 | 211 |
|
193 | 212 | /** |
194 | 213 | * Bias adaptation function as per section 3.4 of RFC 3492. |
195 | | - * http://tools.ietf.org/html/rfc3492#section-3.4 |
| 214 | + * https://tools.ietf.org/html/rfc3492#section-3.4 |
196 | 215 | * @private |
197 | 216 | */ |
198 | 217 | function adapt(delta, numPoints, firstTime) { |
|
307 | 326 | } |
308 | 327 |
|
309 | 328 | /** |
310 | | - * Converts a string of Unicode symbols to a Punycode string of ASCII-only |
311 | | - * symbols. |
| 329 | + * Converts a string of Unicode symbols (e.g. a domain name label) to a |
| 330 | + * Punycode string of ASCII-only symbols. |
312 | 331 | * @memberOf punycode |
313 | 332 | * @param {String} input The string of Unicode symbols. |
314 | 333 | * @returns {String} The resulting Punycode string of ASCII-only symbols. |
|
421 | 440 | } |
422 | 441 |
|
423 | 442 | /** |
424 | | - * Converts a Punycode string representing a domain name to Unicode. Only the |
425 | | - * Punycoded parts of the domain name will be converted, i.e. it doesn't |
426 | | - * matter if you call it on a string that has already been converted to |
427 | | - * Unicode. |
| 443 | + * Converts a Punycode string representing a domain name or an email address |
| 444 | + * to Unicode. Only the Punycoded parts of the input will be converted, i.e. |
| 445 | + * it doesn't matter if you call it on a string that has already been |
| 446 | + * converted to Unicode. |
428 | 447 | * @memberOf punycode |
429 | | - * @param {String} domain The Punycode domain name to convert to Unicode. |
| 448 | + * @param {String} input The Punycoded domain name or email address to |
| 449 | + * convert to Unicode. |
430 | 450 | * @returns {String} The Unicode representation of the given Punycode |
431 | 451 | * string. |
432 | 452 | */ |
433 | | - function toUnicode(domain) { |
434 | | - return mapDomain(domain, function(string) { |
| 453 | + function toUnicode(input) { |
| 454 | + return mapDomain(input, function(string) { |
435 | 455 | return regexPunycode.test(string) |
436 | 456 | ? decode(string.slice(4).toLowerCase()) |
437 | 457 | : string; |
438 | 458 | }); |
439 | 459 | } |
440 | 460 |
|
441 | 461 | /** |
442 | | - * Converts a Unicode string representing a domain name to Punycode. Only the |
443 | | - * non-ASCII parts of the domain name will be converted, i.e. it doesn't |
444 | | - * matter if you call it with a domain that's already in ASCII. |
| 462 | + * Converts a Unicode string representing a domain name or an email address to |
| 463 | + * Punycode. Only the non-ASCII parts of the domain name will be converted, |
| 464 | + * i.e. it doesn't matter if you call it with a domain that's already in |
| 465 | + * ASCII. |
445 | 466 | * @memberOf punycode |
446 | | - * @param {String} domain The domain name to convert, as a Unicode string. |
447 | | - * @returns {String} The Punycode representation of the given domain name. |
| 467 | + * @param {String} input The domain name or email address to convert, as a |
| 468 | + * Unicode string. |
| 469 | + * @returns {String} The Punycode representation of the given domain name or |
| 470 | + * email address. |
448 | 471 | */ |
449 | | - function toASCII(domain) { |
450 | | - return mapDomain(domain, function(string) { |
| 472 | + function toASCII(input) { |
| 473 | + return mapDomain(input, function(string) { |
451 | 474 | return regexNonASCII.test(string) |
452 | 475 | ? 'xn--' + encode(string) |
453 | 476 | : string; |
|
463 | 486 | * @memberOf punycode |
464 | 487 | * @type String |
465 | 488 | */ |
466 | | - 'version': '1.2.3', |
| 489 | + 'version': '1.3.2', |
467 | 490 | /** |
468 | 491 | * An object of methods to convert from JavaScript's internal character |
469 | 492 | * representation (UCS-2) to Unicode code points, and back. |
470 | | - * @see <http://mathiasbynens.be/notes/javascript-encoding> |
| 493 | + * @see <https://mathiasbynens.be/notes/javascript-encoding> |
471 | 494 | * @memberOf punycode |
472 | 495 | * @type Object |
473 | 496 | */ |
|
489 | 512 | typeof define.amd == 'object' && |
490 | 513 | define.amd |
491 | 514 | ) { |
492 | | - define(function() { |
| 515 | + define('punycode', function() { |
493 | 516 | return punycode; |
494 | 517 | }); |
495 | | - } else if (freeExports && !freeExports.nodeType) { |
496 | | - if (freeModule) { // in Node.js or RingoJS v0.8.0+ |
| 518 | + } else if (freeExports && freeModule) { |
| 519 | + if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+ |
497 | 520 | freeModule.exports = punycode; |
498 | 521 | } else { // in Narwhal or RingoJS v0.7.0- |
499 | 522 | for (key in punycode) { |
|
0 commit comments