url: throw descriptive error if url argument to parse() is not a string
Fixes #568.
This commit is contained in:
parent
6f0740e67b
commit
1b0e054737
@ -88,6 +88,10 @@ var protocolPattern = /^([a-z0-9]+:)/i,
|
|||||||
function urlParse(url, parseQueryString, slashesDenoteHost) {
|
function urlParse(url, parseQueryString, slashesDenoteHost) {
|
||||||
if (url && typeof(url) === 'object' && url.href) return url;
|
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 = {},
|
var out = {},
|
||||||
rest = url;
|
rest = url;
|
||||||
|
|
||||||
|
@ -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
|
// Tests below taken from Chiron
|
||||||
// http://code.google.com/p/chironjs/source/browse/trunk/src/test/http/url.js
|
// http://code.google.com/p/chironjs/source/browse/trunk/src/test/http/url.js
|
||||||
|
Loading…
x
Reference in New Issue
Block a user