From 7a2012ac5f9e50f7be91b5584d946667fe6d56f1 Mon Sep 17 00:00:00 2001 From: Tully Date: Wed, 19 Nov 2014 15:37:16 +0100 Subject: [PATCH] fix of https://github.com/nodejitsu/node-http-proxy/issues/738 --- lib/http-proxy/common.js | 21 +++++++++++++++------ test/lib-http-proxy-common-test.js | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index a6aca80b0..779def2ea 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -139,7 +139,7 @@ common.urlJoin = function() { lastIndex = args.length - 1, last = args[lastIndex], lastSegs = last.split('?'), - retSegs; + retSegs = []; args[lastIndex] = lastSegs[0]; @@ -147,11 +147,20 @@ common.urlJoin = function() { // Join all strings, but remove empty strings so we don't get extra slashes from // joining e.g. ['', 'am'] // - retSegs = [ - args.filter(function filter(a) { - return !!a; - }).join('/').replace(/\/+/g, '/') - ]; + + args.filter(function filter(a) { + return !!a; + }).forEach(function(v, idx) { + if(idx != 0){ + v = v.replace(/^\//, ''); + } + if(v) { + + retSegs.push(v); + } + }) + + retSegs = [retSegs.join('/')]; // Only join the query string if it exists so we don't have trailing a '?' // on every request diff --git a/test/lib-http-proxy-common-test.js b/test/lib-http-proxy-common-test.js index 149c4226b..7a434f561 100644 --- a/test/lib-http-proxy-common-test.js +++ b/test/lib-http-proxy-common-test.js @@ -209,7 +209,7 @@ describe('lib/http-proxy/common.js', function () { target: { path: '/forward' }, }, { url: '/?foo=bar//&target=http://foobar.com/' }); - expect(outgoing.path).to.eql('/forward/?foo=bar//&target=http://foobar.com/'); + expect(outgoing.path).to.eql('/forward?foo=bar//&target=http://foobar.com/'); }) });