url: Don't swallow punycode errors
authorisaacs <i@izs.me>
Wed, 6 Jul 2011 20:12:37 +0000 (13:12 -0700)
committerisaacs <i@izs.me>
Wed, 6 Jul 2011 20:17:50 +0000 (13:17 -0700)
lib/url.js

index ed90e5c..a30fa8a 100644 (file)
@@ -222,18 +222,14 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
     // It only converts the part of the domain name that
     // has non ASCII characters. I.e. it dosent matter if
     // you call it with a domain that already is in ASCII.
-    try {
-      var domainArray = out.hostname.split('.');
-      var newOut = [];
-      for (var i = 0; i < domainArray.length; ++i) {
-        var s = domainArray[i];
-        newOut.push(s.match(/[^A-Za-z0-9-]/) ?
-          'xn--' + punycode.encode(s) : s);
-      }
-      out.hostname = newOut.join('.');
-    } catch (e) {
-      // if encode fail for some reason, we just do the classic behavior.
+    var domainArray = out.hostname.split('.');
+    var newOut = [];
+    for (var i = 0; i < domainArray.length; ++i) {
+      var s = domainArray[i];
+      newOut.push(s.match(/[^A-Za-z0-9-]/) ?
+        'xn--' + punycode.encode(s) : s);
     }
+    out.hostname = newOut.join('.');
 
     out.host = ((out.auth) ? out.auth + '@' : '') +
         (out.hostname || '') +