From 70ed1c4273bc64500e8bae9b60d7fd6a19135246 Mon Sep 17 00:00:00 2001 From: koolc Date: Tue, 25 Nov 2014 17:50:36 +0800 Subject: [PATCH] [Bugfix] Allow for multiple ? in outgoing urls. Without this fix urls that had multiple ? in them would drop sections of the url since before there was an assumption of there only being one. --- lib/http-proxy/common.js | 6 ++++-- test/lib-http-proxy-common-test.js | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index a6aca80b0..a4ce19df2 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -141,7 +141,7 @@ common.urlJoin = function() { lastSegs = last.split('?'), retSegs; - args[lastIndex] = lastSegs[0]; + args[lastIndex] = lastSegs.shift(); // // Join all strings, but remove empty strings so we don't get extra slashes from @@ -155,7 +155,9 @@ common.urlJoin = function() { // Only join the query string if it exists so we don't have trailing a '?' // on every request - lastSegs[1] && retSegs.push(lastSegs[1]); + + // Handle case where there could be multiple ? in the URL. + retSegs.concat(lastSegs); return retSegs.join('?') }; diff --git a/test/lib-http-proxy-common-test.js b/test/lib-http-proxy-common-test.js index 149c4226b..ef202ce23 100644 --- a/test/lib-http-proxy-common-test.js +++ b/test/lib-http-proxy-common-test.js @@ -203,13 +203,13 @@ describe('lib/http-proxy/common.js', function () { expect(outgoing.path).to.eql('/forward/static/path'); }) - it('should not modify the query string', function () { + it.only('should not modify the query string', function () { var outgoing = {}; common.setupOutgoing(outgoing, { target: { path: '/forward' }, - }, { url: '/?foo=bar//&target=http://foobar.com/' }); + }, { url: '/?foo=bar//&target=http://foobar.com/?a=1%26b=2&other=2' }); - expect(outgoing.path).to.eql('/forward/?foo=bar//&target=http://foobar.com/'); + expect(outgoing.path).to.eql('/forward/?foo=bar//&target=http://foobar.com/?a=1%26b=2&other=2'); }) });