diff --git a/lib/url.js b/lib/url.js index e4fcf779fac..4f7611da960 100644 --- a/lib/url.js +++ b/lib/url.js @@ -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; diff --git a/test/simple/test-url.js b/test/simple/test-url.js index fdf8bde5962..c6c47292e05 100644 --- a/test/simple/test-url.js +++ b/test/simple/test-url.js @@ -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