add res.redirect("//foo.com") support

This commit is contained in:
TJ Holowaychuk
2012-07-18 09:29:11 -07:00
parent d66f0e5eb9
commit a93d375acc
2 changed files with 20 additions and 1 deletions

View File

@@ -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

View File

@@ -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){