mirror of
https://github.com/zebrajr/express.git
synced 2026-01-15 12:15:27 +00:00
Added support for .. in redirects as well
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user