From 7bad3fbca4168269bede5d25dfe0134660efc4a9 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 28 Jan 2016 13:22:28 -0500 Subject: [PATCH] fix(common) urlJoin replace: ":/" -> "http?s:/" --- lib/http-proxy/common.js | 5 ++++- test/lib-http-proxy-common-test.js | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index d143cf9f1..2602305d7 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -182,7 +182,10 @@ common.urlJoin = function() { // joining e.g. ['', 'am'] // retSegs = [ - args.filter(Boolean).join('/').replace(/\/+/g, '/').replace(/:\//g, '://') + args.filter(Boolean).join('/') + .replace(/\/+/g, '/') + .replace('http:/', 'http://') + .replace('https:/', 'https://') ]; // Only join the query string if it exists so we don't have trailing a '?' diff --git a/test/lib-http-proxy-common-test.js b/test/lib-http-proxy-common-test.js index e118f2e61..ef99ca109 100644 --- a/test/lib-http-proxy-common-test.js +++ b/test/lib-http-proxy-common-test.js @@ -241,6 +241,28 @@ describe('lib/http-proxy/common.js', function () { expect(outgoing.path).to.eql('/' + google); }); + it('should not replace :\ to :\\ when no https word before', function () { + var outgoing = {}; + var google = 'https://google.com:/join/join.js' + common.setupOutgoing(outgoing, { + target: url.parse('http://sometarget.com:80'), + toProxy: true, + }, { url: google }); + + expect(outgoing.path).to.eql('/' + google); + }); + + it('should not replace :\ to :\\ when no http word before', function () { + var outgoing = {}; + var google = 'http://google.com:/join/join.js' + common.setupOutgoing(outgoing, { + target: url.parse('http://sometarget.com:80'), + toProxy: true, + }, { url: google }); + + expect(outgoing.path).to.eql('/' + google); + }); + describe('when using ignorePath', function () { it('should ignore the path of the `req.url` passed in but use the target path', function () { var outgoing = {};