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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Tully committed Nov 19, 2014
1 parent aba505d commit 7a2012a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions lib/http-proxy/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,28 @@ common.urlJoin = function() {
lastIndex = args.length - 1,
last = args[lastIndex],
lastSegs = last.split('?'),
retSegs;
retSegs = [];

args[lastIndex] = lastSegs[0];

//
// 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
Expand Down
2 changes: 1 addition & 1 deletion test/lib-http-proxy-common-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/');
})
});

Expand Down

0 comments on commit 7a2012a

Please sign in to comment.