Skip to content
Myr

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

3 files+30 added−12 removed

modified:lib/response.js+6 added-5 removed
12 unmodified lines
13 , 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;2021/**
611 unmodified lines
633 */634635res.location = function(url){636 var app = this.app636 , req = this.req;637 , req = this.req638 , path;639640 // setup redirect map641 var map = { back: req.get('Referrer') || '/' };642
1 unmodified line
644 url = map[url] || url;645646 // relative647 if (!~url.indexOf('://') && 0 != url.indexOf('//')) {646 var path647648 // 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 lines
modified:test/res.location.js+19 added-2 removed
modified:test/res.redirect.js+5 added-5 removed
208 unmodified lines
209 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');214215 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');219220 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 lines
230 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