url.parse(url, true) defaults query field to {}
This commit is contained in:
parent
8db0bbe0dc
commit
6f726cf8c7
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user