Skip to content

Commit 7bad3fb

Browse files
committed
fix(common) urlJoin replace: ":/" -> "http?s:/"
1 parent 268994e commit 7bad3fb

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/http-proxy/common.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ common.urlJoin = function() {
182182
// joining e.g. ['', 'am']
183183
//
184184
retSegs = [
185-
args.filter(Boolean).join('/').replace(/\/+/g, '/').replace(/:\//g, '://')
185+
args.filter(Boolean).join('/')
186+
.replace(/\/+/g, '/')
187+
.replace('http:/', 'http://')
188+
.replace('https:/', 'https://')
186189
];
187190

188191
// Only join the query string if it exists so we don't have trailing a '?'

test/lib-http-proxy-common-test.js

+22
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,28 @@ describe('lib/http-proxy/common.js', function () {
241241
expect(outgoing.path).to.eql('/' + google);
242242
});
243243

244+
it('should not replace :\ to :\\ when no https word before', function () {
245+
var outgoing = {};
246+
var google = 'https://google.com:/join/join.js'
247+
common.setupOutgoing(outgoing, {
248+
target: url.parse('http://sometarget.com:80'),
249+
toProxy: true,
250+
}, { url: google });
251+
252+
expect(outgoing.path).to.eql('/' + google);
253+
});
254+
255+
it('should not replace :\ to :\\ when no http word before', function () {
256+
var outgoing = {};
257+
var google = 'http://google.com:/join/join.js'
258+
common.setupOutgoing(outgoing, {
259+
target: url.parse('http://sometarget.com:80'),
260+
toProxy: true,
261+
}, { url: google });
262+
263+
expect(outgoing.path).to.eql('/' + google);
264+
});
265+
244266
describe('when using ignorePath', function () {
245267
it('should ignore the path of the `req.url` passed in but use the target path', function () {
246268
var outgoing = {};

0 commit comments

Comments
 (0)