Skip to content

Urgent: Fix breaking bug on url joining resulting in paths like ///path. #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/http-proxy/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
? url.parse(req.url).path
: req.url;

outgoing.path = targetPath
? targetPath + '/' + outgoingPath
: outgoingPath;
outgoing.path = common.urlJoin(targetPath, outgoingPath);

return outgoing;
};
Expand Down Expand Up @@ -109,4 +107,12 @@ common.getPort = function(req) {
return res ?
res[1] :
req.connection.pair ? '443' : '80' ;
}
};

// OS-agnostic join (doesn't break on URLs like path.join does on Windows)
common.urlJoin = function() {
var args = Array.prototype.slice.call(arguments);
// Join all strings, but remove empty strings so we don't get extra slashes from
// joining e.g. ['', 'am']
return args.filter(function(a) { return !!a; }).join('/').replace(/\/+/g, '/');
};
9 changes: 9 additions & 0 deletions test/lib-http-proxy-common-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ describe('lib/http-proxy/common.js', function () {

expect(outgoing.path).to.eql('hi');
})

it('should properly join paths', function () {
var outgoing = {};
common.setupOutgoing(outgoing, {
target: { path: '/forward' },
}, { url: '/static/path' });

expect(outgoing.path).to.eql('/forward/static/path');
})
});

describe('#setupSocket', function () {
Expand Down