diff --git a/lib/url.js b/lib/url.js index bb11144f7a33bc..3c3e91d2a99189 100644 --- a/lib/url.js +++ b/lib/url.js @@ -548,7 +548,7 @@ Url.prototype.format = function() { var pathname = this.pathname || ''; var hash = this.hash || ''; var host = false; - var query = ''; + var query; if (this.host) { host = auth + this.host; @@ -563,6 +563,8 @@ Url.prototype.format = function() { if (this.query !== null && typeof this.query === 'object') query = querystring.stringify(this.query); + else + query = this.query; var search = this.search || (query && ('?' + query)) || ''; diff --git a/test/parallel/test-url.js b/test/parallel/test-url.js index 760303e98bb6bb..1e3f923e2741c6 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -1586,3 +1586,6 @@ for (let i = 0; i < throws.length; i++) { } assert(url.format('') === ''); assert(url.format({}) === ''); + +// https://github.com/nodejs/node/issues/6004 +assert.equal(url.format({pathname:'/foo', query: 'bar=baz'}), '/foo?bar=baz');