Skip to content

Commit

Permalink
Update common.js
Browse files Browse the repository at this point in the history
Bugfix: outgoing url is wrong when the source url is 'http://a.b.c/d/??e/a.js,f/b.js,g/c.js?t=123456' (a combo url).
  • Loading branch information
koolc authored and samccone committed Dec 1, 2014
1 parent 361d4e3 commit 4a6c8e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions lib/http-proxy/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -155,7 +155,12 @@ 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]);
// Maybe there are many '?' in the url,
// such as 'http://a.b.c/d/??e/a.js,f/b.js,g/c.js?t=123456'(a combo request url),
// so to use `forEach`.
lastSegs.forEach(function (slice) {
retSegs.push(slice);
});

return retSegs.join('?')
};
6 changes: 3 additions & 3 deletions test/lib-http-proxy-common-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('should not modify the query string and hash 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=some#id12' });

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=some#id12');
})
});

Expand Down

0 comments on commit 4a6c8e2

Please sign in to comment.