Skip to content
Browse files

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

Fixes #568.
  • Loading branch information...
1 parent 0599cb7 commit a0e23bd4fd32489e073405787b8cf09d9653c4a1 @bnoordhuis committed Jul 20, 2011
Showing with 19 additions and 0 deletions.
  1. +4 −0 lib/url.js
  2. +15 −0 test/simple/test-url.js
View
4 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;
View
15 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

0 comments on commit a0e23bd

Please sign in to comment.
Something went wrong with that request. Please try again.