url: throw descriptive error if url argument to parse() is not a string

Fixes #568.
This commit is contained in:
Ben Noordhuis 2011-07-20 22:15:41 +02:00
parent 6f0740e67b
commit 1b0e054737
2 changed files with 19 additions and 0 deletions

View 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;

View 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