Browse files

punycode: Update to v1.0.0

  • Loading branch information...
1 parent 70a393e commit 483edbdf1aef40c208f6c96efbbcc3c34122e5f2 @mathiasbynens mathiasbynens committed with isaacs Feb 24, 2012
Showing with 18 additions and 19 deletions.
  1. +18 −19 lib/punycode.js
View
37 lib/punycode.js
@@ -1,9 +1,4 @@
-/*!
- * Punycode.js <http://mths.be/punycode>
- * Copyright 2011 Mathias Bynens <http://mathiasbynens.be/>
- * Available under MIT license <http://mths.be/mit>
- */
-
+/*! http://mths.be/punycode by @mathias */
;(function(root) {
/**
@@ -34,7 +29,7 @@
delimiter = '-', // '\x2D'
/** Regular expressions */
- regexNonASCII = /[^ -~]/, // matches unprintable ASCII chars + non-ASCII chars
+ regexNonASCII = /[^ -~]/, // unprintable ASCII chars + non-ASCII chars
regexPunycode = /^xn--/,
/** Error messages */
@@ -97,14 +92,17 @@
}
/**
- * Creates an array containing the decimal code points of each character in
- * the string.
- * @see `punycode.utf16.encode`
- * @see <http://tools.ietf.org/html/rfc2781>
- * @memberOf punycode.utf16
+ * Creates an array containing the decimal code points of each Unicode
+ * character in the string. While JavaScript uses UCS-2 internally,
+ * this function will convert a pair of surrogate halves (each of which
+ * UCS-2 exposes as separate characters) into a single code point,
+ * matching UTF-16.
+ * @see `punycode.ucs2.encode`
+ * @see <http://mathiasbynens.be/notes/javascript-encoding>
+ * @memberOf punycode.ucs2
* @name decode
- * @param {String} string The Unicode input string.
- * @returns {Array} The new array.
+ * @param {String} string The Unicode input string (UCS-2).
+ * @returns {Array} The new array of code points.
*/
function utf16decode(string) {

How come this method is still called utf16decode and not ucs2decode? This doesn’t match Punycode.js v1.0.0. It also doesn’t match this commit: cacd651.

@bnoordhuis
Node.js Foundation member

You're looking at a commit from the v0.6 branch. cacd651 only exists in the master branch.

Yes, but I’m wondering why the v0.6 branch has Punycode v1.0.0 but with a different API than the real v1.0.0 (as in the master branch). Confusing :)

To clarify, I wonder why Node v0.6 has require('punycode').version == '1.0.0' even though the API it exposes it not that of Punycode.js v1.0.0 at all. /cc @isaacs

@isaacs, any idea? Should I file a bug on this?

@koichik
koichik added a note Jun 1, 2012

#2456 (punycode v0.3.0) was landed in master, but not v0.6.

@koichik Thanks, I get that, but that doesn’t answer 483edbd#commitcomment-1387233. What’s currently in v0.6 is some sort of Frankenstein version that declares itself as Punycode.js v1.0.0 but has v0.3.0’s API.

@koichik
koichik added a note Jun 1, 2012

@mathiasbynens - utf16/ucs2 stuff was included #2456. Please note that we apply patches not the whole file. So, we should apply #2456 in v0.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
var output = [],
@@ -133,7 +131,7 @@
* @memberOf punycode.utf16
* @name encode
* @param {Array} codePoints The array of decimal code points.
- * @returns {String} The new string.
+ * @returns {String} The new Unicode string (UCS-2).
*/
function utf16encode(array) {
return map(array, function(value) {
@@ -283,7 +281,7 @@
}
i += digit * w;
- t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
+ t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
if (digit < t) {
break;
@@ -406,7 +404,7 @@
if (currentValue == n) {
// Represent delta as a generalized variable-length integer
for (q = delta, k = base; /* no condition */; k += base) {
- t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
+ t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
if (q < t) {
break;
}
@@ -475,10 +473,11 @@
* @memberOf punycode
* @type String
*/
- 'version': '0.2.1',
+ 'version': '1.0.0',
/**
* An object of methods to convert from JavaScript's internal character
- * representation to Unicode and back.
+ * representation (UCS-2) to decimal Unicode code points, and back.
+ * @see <http://mathiasbynens.be/notes/javascript-encoding>
* @memberOf punycode

Same here, where the methods are exposed on the punycode object.

utf16 should be ucs2, as per the docs, and as in https://github.com/joyent/node/blob/cacd651ec6944c7b6596d1c199ab9a37ba9abf7c/lib/punycode.js.

If not, punycode.version shouldn’t be '1.0.0'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
* @type Object
*/

0 comments on commit 483edbd

Please sign in to comment.