url: throw descriptive error if url argument to parse() is not a string
authorBen Noordhuis <info@bnoordhuis.nl>
Wed, 20 Jul 2011 20:15:41 +0000 (22:15 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Wed, 20 Jul 2011 22:51:48 +0000 (00:51 +0200)
Fixes #568.

lib/url.js
test/simple/test-url.js

index e4fcf77..4f7611d 100644 (file)
@@ -88,6 +88,10 @@ var protocolPattern = /^([a-z0-9]+:)/i,
 function urlParse(url, parseQueryString, slashesDenoteHost) {
   if (url && typeof(url) === 'object' && url.href) return url;
 
+  if (typeof url !== 'string') {
+    throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
+  }
+
   var out = {},
       rest = url;
 
index fdf8bde..c6c4729 100644 (file)
@@ -545,6 +545,21 @@ relativeTests.forEach(function(relativeTest) {
 });
 
 
+// https://github.com/joyent/node/issues/568
+[
+  undefined,
+  null,
+  true,
+  false,
+  0.0,
+  0,
+  [],
+  {}
+].forEach(function(val) {
+  assert.throws(function() { url.parse(val); }, TypeError);
+});
+
+
 //
 // Tests below taken from Chiron
 // http://code.google.com/p/chironjs/source/browse/trunk/src/test/http/url.js