diff --git a/lib/response.js b/lib/response.js index 61fff230..6ef765e0 100644 --- a/lib/response.js +++ b/lib/response.js @@ -518,7 +518,7 @@ res.redirect = function(url){ url = map[url] || url; // relative - if (!~url.indexOf('://')) { + if (!~url.indexOf('://') && 0 != url.indexOf('//')) { var path = app.path(); // relative to path diff --git a/test/res.redirect.js b/test/res.redirect.js index e78e300b..3bca406a 100644 --- a/test/res.redirect.js +++ b/test/res.redirect.js @@ -19,6 +19,25 @@ describe('res', function(){ done(); }) }) + + describe('with leading //', function(){ + it('should pass through scheme-relative urls', function(done){ + var app = express(); + + app.use(function(req, res){ + res.redirect('//cuteoverload.com'); + }); + + request(app) + .get('/') + .set('Host', 'example.com') + .end(function(err, res){ + res.headers.should.have.property('location', '//cuteoverload.com'); + done(); + }) + }) + }) + describe('with leading /', function(){ it('should construct scheme-relative urls', function(done){