diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index 59ece4dfb..225324ebf 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -80,7 +80,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) { // Remark: Can we somehow not use url.parse as a perf optimization? // var outgoingPath = !options.toProxy - ? url.parse(req.url).path + ? (url.parse(req.url).path || '/') : req.url; outgoing.path = common.urlJoin(targetPath, outgoingPath); diff --git a/test/lib-http-proxy-common-test.js b/test/lib-http-proxy-common-test.js index 007ba39a4..3c6ebd1db 100644 --- a/test/lib-http-proxy-common-test.js +++ b/test/lib-http-proxy-common-test.js @@ -299,6 +299,17 @@ describe('lib/http-proxy/common.js', function () { expect(outgoing.ciphers).eql('my-ciphers'); expect(outgoing.secureProtocol).eql('my-secure-protocol'); }); + + // url.parse('').path => null + it('should not pass null as last arg to #urlJoin', function(){ + var outgoing = {}; + common.setupOutgoing(outgoing, {target: + { path: '' } + }, { url : '' }); + + expect(outgoing.path).to.be('/'); + }); + }); describe('#setupSocket', function () {