url.parse(url, true) defaults query field to {}

This commit is contained in:
Jeremy Martin 2010-12-20 16:21:02 -05:00 committed by Ryan Dahl
parent 8db0bbe0dc
commit 6f726cf8c7
3 changed files with 21 additions and 1 deletions

View File

@ -136,7 +136,7 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq) {
eq = eq || '=';
var obj = {};
if (typeof qs !== 'string') {
if (typeof qs !== 'string' || qs.length === 0) {
return obj;
}

View File

@ -98,6 +98,9 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
out.query = querystring.parse(out.query);
}
rest = rest.slice(0, qm);
} else if (parseQueryString) {
// no query string, but parseQueryString still requested
out.query = {};
}
if (rest) out.pathname = rest;

View File

@ -192,6 +192,23 @@ var parseTestsWithQueryString = {
'baz': 'quux'
},
'pathname': '/foo/bar'
},
'http://example.com' : {
'href': 'http://example.com',
'protocol': 'http:',
'slashes': true,
'host': 'example.com',
'hostname': 'example.com',
'query': {}
},
'http://example.com?' : {
'href': 'http://example.com?',
'protocol': 'http:',
'slashes': true,
'host': 'example.com',
'hostname': 'example.com',
'search': '?',
'query': {}
}
};
for (var u in parseTestsWithQueryString) {