Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 7a2012a

Browse files
author
Tully
committed
1 parent aba505d commit 7a2012a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/http-proxy/common.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,28 @@ common.urlJoin = function() {
139139
lastIndex = args.length - 1,
140140
last = args[lastIndex],
141141
lastSegs = last.split('?'),
142-
retSegs;
142+
retSegs = [];
143143

144144
args[lastIndex] = lastSegs[0];
145145

146146
//
147147
// Join all strings, but remove empty strings so we don't get extra slashes from
148148
// joining e.g. ['', 'am']
149149
//
150-
retSegs = [
151-
args.filter(function filter(a) {
152-
return !!a;
153-
}).join('/').replace(/\/+/g, '/')
154-
];
150+
151+
args.filter(function filter(a) {
152+
return !!a;
153+
}).forEach(function(v, idx) {
154+
if(idx != 0){
155+
v = v.replace(/^\//, '');
156+
}
157+
if(v) {
158+
159+
retSegs.push(v);
160+
}
161+
})
162+
163+
retSegs = [retSegs.join('/')];
155164

156165
// Only join the query string if it exists so we don't have trailing a '?'
157166
// on every request

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ describe('lib/http-proxy/common.js', function () {
209209
target: { path: '/forward' },
210210
}, { url: '/?foo=bar//&target=http://foobar.com/' });
211211

212-
expect(outgoing.path).to.eql('/forward/?foo=bar//&target=http://foobar.com/');
212+
expect(outgoing.path).to.eql('/forward?foo=bar//&target=http://foobar.com/');
213213
})
214214
});
215215

0 commit comments

Comments
 (0)