Added support for .. in redirects as well

This commit is contained in:
Tj Holowaychuk
2011-12-06 16:44:15 -08:00
parent d7dfe3e812
commit 88f154fecd
2 changed files with 21 additions and 4 deletions

View File

@@ -474,9 +474,8 @@ res.redirect = function(url){
var path = app.path();
// relative to path
if (0 == url.indexOf('./')) {
path = req.path;
url = path + '/' + url.slice(2)
if (0 == url.indexOf('./') || 0 == url.indexOf('..')) {
url = req.path + '/' + url;
// relative to mount-point
} else if ('/' != url[0]) {
url = path + '/' + url;

View File

@@ -50,7 +50,25 @@ describe('res', function(){
.get('/post/1')
.set('Host', 'example.com')
.end(function(res){
res.headers.should.have.property('location', 'http://example.com/post/1/edit');
res.headers.should.have.property('location', 'http://example.com/post/1/./edit');
done();
})
})
})
describe('with leading ../', function(){
it('should construct path-relative urls', function(done){
var app = express();
app.use(function(req, res){
res.redirect('../new');
});
request(app)
.get('/post/1')
.set('Host', 'example.com')
.end(function(res){
res.headers.should.have.property('location', 'http://example.com/post/1/../new');
done();
})
})