Permalink
Browse files

Only punycode non-ASCII

  • Loading branch information...
1 parent d7d744b commit 533250645b7cec97ed541c10179bb4af26676305 @stash stash committed Apr 23, 2012
Showing with 6 additions and 1 deletion.
  1. +1 −1 lib/cookie.js
  2. +5 −0 test.js
View
2 lib/cookie.js
@@ -206,7 +206,7 @@ function canonicalDomain(str) {
str = str.trim().replace(/^\./,''); // S4.1.2.3 & S5.2.3: ignore leading .
// convert to IDN if any non-ASCII characters
- if (punycode && /[\u0080-]/)
+ if (punycode && /[^\u0001-\u007f]/.test(str))
str = punycode.toASCII(str);
return str.toLowerCase();
View
5 test.js
@@ -491,6 +491,11 @@ vows.describe('Cookie Jar').addBatch({
c.domain = "EXAMPLE...ca.";
assert.equal(c.canonicalizedDomain(), "example...ca.");
},
+ "IDN": function() {
+ var c = new Cookie();
+ c.domain = "δοκιμή.δοκιμή"; // "test.test" in greek
+ assert.equal(c.canonicalizedDomain(), "xn--jxalpdlp.xn--jxalpdlp");
+ }
}
}).addBatch({
"Domain Match":matchVows(tough.domainMatch, [

0 comments on commit 5332506

Please sign in to comment.