Browse Source

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

v0.7.4-release
Jeremy Martin 14 years ago
committed by Ryan Dahl
parent
commit
6f726cf8c7
  1. 2
      lib/querystring.js
  2. 3
      lib/url.js
  3. 17
      test/simple/test-url.js

2
lib/querystring.js

@ -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;
}

3
lib/url.js

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

17
test/simple/test-url.js

@ -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…
Cancel
Save