Merge pull request #1802 from kapouer/patch-1
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Remove leading ./ when using res.location('./relative')
authored by Jonathan Ong · committed by Jonathan Ong · parents 6e3f388, c9865b8 · Browse files · 3 files·+30 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+30 added−12 removed
- tests:+24 added−7 removed
- other:+6 added−5 removed
Provenance
- Commit
2bc703c- Tree
af459a9- Author
Jonathan Ong <jonathanrichardong@gmail.com>- Committer
Jonathan Ong <jonathanrichardong@gmail.com>- Parent 1
6e3f388- Parent 2
c9865b8
3 files changed+30 added−12 removed
modified:lib/response.js+6 added-5 removed
12 unmodified lines13 , statusCodes = http.STATUS_CODES14 , cookie = require('cookie')15 , send = require('send')16 , mime = connect.mime17+ , resolve = require('url').resolve18 , basename = path.basename19 , extname = path.extname;20 21 /**611 unmodified lines633 */634 635 res.location = function(url){636 var app = this.app636- , req = this.req;637+ , req = this.req638+ , path;639 640 // setup redirect map641 var map = { back: req.get('Referrer') || '/' };642 1 unmodified line644 url = map[url] || url;645 646 // relative647 if (!~url.indexOf('://') && 0 != url.indexOf('//')) {646- var path647-648 // relative to path649 if ('.' == url[0]) {650- path = req.originalUrl.split('?')[0]651- url = path + ('/' == path[path.length - 1] ? '' : '/') + url;650+ path = req.originalUrl.split('?')[0];651+ path = path + ('/' == path[path.length - 1] ? '' : '/');652+ url = resolve(path, url);653 // relative to mount-point654 } else if ('/' != url[0]) {655 path = app.path();656 url = path + '/' + url;147 unmodified linesmodified:test/res.location.js+19 added-2 removed
62 unmodified lines636465666767686970718 unmodified lines80818283848485868788899091929394959697989910010110210310410510610710810979 unmodified lines62 unmodified lines
request(app) .get('/post/1') .end(function(err, res){ res.headers.should.have.property('location', '/post/1/./edit'); res.headers.should.have.property('location', '/post/1/edit'); done(); }) }) })8 unmodified lines
request(app) .get('/post/1') .end(function(err, res){ res.headers.should.have.property('location', '/post/1/../new'); res.headers.should.have.property('location', '/post/new'); done(); }) }) })
describe('with leading ./ and containing ..', function(){ it('should construct path-relative urls', function(done){ var app = express();
app.use(function(req, res){ res.location('./skip/../../new').end(); });
request(app) .get('/post/1') .end(function(err, res){ res.headers.should.have.property('location', '/post/new'); done(); }) }) }) describe('without leading /', function(){ it('should construct mount-point relative urls', function(done){ var app = express();79 unmodified linesmodified:test/res.redirect.js+5 added-5 removed
208 unmodified lines209 it('should preserve context when redirecting nested applications at any depth', function(done){210 request(root)211 .get('/depth1')212 .end(function(err, res){213- res.headers.should.have.property('location', '/depth1/./index');213+ res.headers.should.have.property('location', '/depth1/index');214 215 request(root)216 .get('/depth1/depth2')217 .end(function(err, res){218- res.headers.should.have.property('location', '/depth1/depth2/./index');218+ res.headers.should.have.property('location', '/depth1/depth2/index');219 220 request(root)221 .get('/depth1/depth2/depth3')222 .end(function(err, res){223- res.headers.should.have.property('location', '/depth1/depth2/depth3/./index');223+ res.headers.should.have.property('location', '/depth1/depth2/depth3/index');224 done();225 })226 })227 });2 unmodified lines230 it('should redirect correctly for nested applications that have been remounted', function(done){231 request(root)232 .get('/depth2')233 .end(function(err, res){234- res.headers.should.have.property('location', '/depth2/./index');234+ res.headers.should.have.property('location', '/depth2/index');235 request(root)236 .get('/depth3')237 .end(function(err, res){238- res.headers.should.have.property('location', '/depth3/./index');238+ res.headers.should.have.property('location', '/depth3/index');239 done();240 })241 })242 })2 unmodified lines