Skip to content

Commit

Permalink
Fix handling of URLs containing :// in the path
Browse files Browse the repository at this point in the history
fixes #2421
  • Loading branch information
aredridel authored and dougwilson committed Oct 29, 2014
1 parent d40dc65 commit eabd456
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions History.md
@@ -1,3 +1,8 @@
unreleased
==========

* Fix handling of URLs containing `://` in the path

4.10.0 / 2014-10-23
===================

Expand Down
2 changes: 1 addition & 1 deletion lib/router/index.js
Expand Up @@ -126,7 +126,7 @@ proto.handle = function(req, res, done) {

var search = 1 + req.url.indexOf('?');
var pathlength = search ? search - 1 : req.url.length;
var fqdn = 1 + req.url.substr(0, pathlength).indexOf('://');
var fqdn = req.url[0] !== '/' && 1 + req.url.substr(0, pathlength).indexOf('://');
var protohost = fqdn ? req.url.substr(0, req.url.indexOf('/', 2 + fqdn)) : '';
var idx = 0;
var removed = '';
Expand Down
17 changes: 17 additions & 0 deletions test/Router.js
Expand Up @@ -219,6 +219,23 @@ describe('Router', function(){
});
});

it('should ignore FQDN in path', function (done) {
var request = { hit: 0, url: '/proxy/http://example.com/blog/post/1', method: 'GET' };
var router = new Router();

router.use('/proxy', function (req, res, next) {
assert.equal(req.hit++, 0);
assert.equal(req.url, '/http://example.com/blog/post/1');
next();
});

router.handle(request, {}, function (err) {
if (err) return done(err);
assert.equal(request.hit, 1);
done();
});
});

it('should adjust FQDN req.url', function (done) {
var request = { hit: 0, url: 'http://example.com/blog/post/1', method: 'GET' };
var router = new Router();
Expand Down

0 comments on commit eabd456

Please sign in to comment.