From 1b0e054737b207977981e0fc818b013ba8bb0caa Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 20 Jul 2011 22:15:41 +0200 Subject: [PATCH] url: throw descriptive error if url argument to parse() is not a string Fixes #568. --- lib/url.js | 4 ++++ test/simple/test-url.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/url.js b/lib/url.js index e4fcf77..4f7611d 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 fdf8bde..c6c4729 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 -- 2.7.4