Skip to content
Myr

Delete `back` as a magic string (#5933)

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

authored by Blake Embrey · committed by GitHub · parent 6c98f80 · Browse files · 6 files+6 added−76 removed
This commit

State

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

Diff stats

6 files+6 added−76 removed

  • tests:+0 added−58 removed
  • other:+6 added−18 removed

6 files+6 added−76 removed

modified:examples/auth/index.js+1 added-1 removed
modified:examples/cookies/index.js+2 added-2 removed
modified:examples/route-separation/user.js+1 added-1 removed
41 unmodified lines
42 // validation and save back to the db43 var user = req.body.user;44 req.user.name = user.name;45 req.user.email = user.email;46 res.redirect('back');46 res.redirect(req.get('Referrer') || '/');47};
modified:lib/response.js+1 added-14 removed
783 unmodified lines
784 * @public785 */786787res.location = function location(url) {788 var loc;789790 // "back" is an alias for the referrer791 if (url === 'back') {792 loc = this.req.get('Referrer') || '/';793 } else {794 loc = String(url);795 }796797 return this.set('Location', encodeUrl(loc));788 return this.set('Location', encodeUrl(url));789};790791/**792 * Redirect to the given `url` with optional response `status`793 * defaulting to 302.794 *804 * The resulting `url` is determined by `res.location()`, so805 * it will play nicely with mounted apps, relative paths,806 * `"back"` etc.807 *795 * Examples:796 *797 * res.redirect('/foo/bar');798 * res.redirect('http://example.com');
229 unmodified lines
modified:test/res.location.js-58 removed
44 unmodified lines
45 .expect('Location', 'https://google.com?q=%E2%98%83%20%C2%A710')46 .expect(200, done)47 })4849 describe('when url is "back"', function () {50 it('should set location from "Referer" header', function (done) {51 var app = express()5253 app.use(function (req, res) {54 res.location('back').end()55 })5657 request(app)58 .get('/')59 .set('Referer', '/some/page.html')60 .expect('Location', '/some/page.html')61 .expect(200, done)62 })6364 it('should set location from "Referrer" header', function (done) {65 var app = express()6667 app.use(function (req, res) {68 res.location('back').end()69 })7071 request(app)72 .get('/')73 .set('Referrer', '/some/page.html')74 .expect('Location', '/some/page.html')75 .expect(200, done)76 })7778 it('should prefer "Referrer" header', function (done) {79 var app = express()8081 app.use(function (req, res) {82 res.location('back').end()83 })8485 request(app)86 .get('/')87 .set('Referer', '/some/page1.html')88 .set('Referrer', '/some/page2.html')89 .expect('Location', '/some/page2.html')90 .expect(200, done)91 })9293 it('should set the header to "/" without referrer', function (done) {94 var app = express()9596 app.use(function (req, res) {97 res.location('back').end()98 })99100 request(app)101 .get('/')102 .expect('Location', '/')103 .expect(200, done)104 })105 })10649 it('should encode data uri1', function (done) {50 var app = express()51 app.use(function (req, res) {52 res.location('data:text/javascript,export default () => { }').end();
264 unmodified lines
modified:History.md+1 added
5 unmodified lines
6 * `res.status()` accepts only integers, and input must be greater than 99 and less than 10007 * will throw a `RangeError: Invalid status code: ${code}. Status code must be greater than 99 and less than 1000.` for inputs outside this range8 * will throw a `TypeError: Invalid status code: ${code}. Status code must be an integer.` for non integer inputs9 * deps: send@1.0.010 * `res.redirect('back')` and `res.location('back')` is no longer a supported magic string, explicitly use `req.get('Referrer') || '/'`.11* change:12 - `res.clearCookie` will ignore user provided `maxAge` and `expires` options13* deps: cookie-signature@^1.2.114* deps: debug@4.3.6
3813 unmodified lines