Skip to content
Myr

Added support for .. in redirects as well

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent d7dfe3e · Browse files · 2 files+21 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+21 added−4 removed

  • tests:+19 added−1 removed
  • other:+2 added−3 removed

2 files+21 added−4 removed

modified:lib/response.js+2 added-3 removed
472 unmodified lines
473 if (!~url.indexOf('://')) {474 var path = app.path();475476 // relative to path477 if (0 == url.indexOf('./')) {478 path = req.path;479 url = path + '/' + url.slice(2)477 if (0 == url.indexOf('./') || 0 == url.indexOf('..')) {478 url = req.path + '/' + url;479 // relative to mount-point480 } else if ('/' != url[0]) {481 url = path + '/' + url;482 }
93 unmodified lines
modified:test/res.redirect.js+19 added-1 removed
48 unmodified lines
49 request(app)50 .get('/post/1')51 .set('Host', 'example.com')52 .end(function(res){53 res.headers.should.have.property('location', 'http://example.com/post/1/edit');53 res.headers.should.have.property('location', 'http://example.com/post/1/./edit');54 done();55 })56 })57 })5859 describe('with leading ../', function(){60 it('should construct path-relative urls', function(done){61 var app = express();6263 app.use(function(req, res){64 res.redirect('../new');65 });6667 request(app)68 .get('/post/1')69 .set('Host', 'example.com')70 .end(function(res){71 res.headers.should.have.property('location', 'http://example.com/post/1/../new');72 done();73 })74 })75 })76 77 describe('without leading /', function(){78 it('should construct mount-point relative urls', function(done){79 var app = express();
157 unmodified lines