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
Provenance
- Commit
bdd81f8- Tree
1bd0ce7- Author
Blake Embrey <hello@blakeembrey.com>- Committer
GitHub <noreply@github.com>- Parent
6c98f80
6 files changed+6 added−76 removed
modified:examples/auth/index.js+1 added-1 removed
114 unmodified linesExpand all11511611711811911912012112212311 unmodified lines114 unmodified linesExpand all req.session.user = user; req.session.success = 'Authenticated as ' + user.name + ' click to <a href="/logout">logout</a>. ' + ' You may now access <a href="/restricted">/restricted</a>.'; res.redirect('back'); res.redirect(req.get('Referrer') || '/'); }); } else { req.session.error = 'Authentication failed, please check your ' + ' username and password.'11 unmodified linesmodified:examples/cookies/index.js+2 added-2 removed
31 unmodified lines3233343536363738394041424344454646474849503 unmodified lines31 unmodified lines});
app.get('/forget', function(req, res){ res.clearCookie('remember'); res.redirect('back'); res.redirect(req.get('Referrer') || '/');});
app.post('/', function(req, res){ var minute = 60000;
if (req.body && req.body.remember) { res.cookie('remember', 1, { maxAge: minute }) }
res.redirect('back'); res.redirect(req.get('Referrer') || '/');});
/* istanbul ignore next */if (!module.parent) {3 unmodified linesmodified:examples/route-separation/user.js+1 added-1 removed
41 unmodified lines42 // 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 lines784 * @public785 */786 787 res.location = function location(url) {788- var loc;789-790- // "back" is an alias for the referrer791- if (url === 'back') {792- loc = this.req.get('Referrer') || '/';793- } else {794- loc = String(url);795- }796-797- return this.set('Location', encodeUrl(loc));788+ return this.set('Location', encodeUrl(url));789 };790 791 /**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 linesmodified:test/res.location.js-58 removed
44 unmodified lines45 .expect('Location', 'https://google.com?q=%E2%98%83%20%C2%A710')46 .expect(200, done)47 })48 49- describe('when url is "back"', function () {50- it('should set location from "Referer" header', function (done) {51- var app = express()52-53- app.use(function (req, res) {54- res.location('back').end()55- })56-57- request(app)58- .get('/')59- .set('Referer', '/some/page.html')60- .expect('Location', '/some/page.html')61- .expect(200, done)62- })63-64- it('should set location from "Referrer" header', function (done) {65- var app = express()66-67- app.use(function (req, res) {68- res.location('back').end()69- })70-71- request(app)72- .get('/')73- .set('Referrer', '/some/page.html')74- .expect('Location', '/some/page.html')75- .expect(200, done)76- })77-78- it('should prefer "Referrer" header', function (done) {79- var app = express()80-81- app.use(function (req, res) {82- res.location('back').end()83- })84-85- 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- })92-93- it('should set the header to "/" without referrer', function (done) {94- var app = express()95-96- app.use(function (req, res) {97- res.location('back').end()98- })99-100- request(app)101- .get('/')102- .expect('Location', '/')103- .expect(200, done)104- })105- })106-49 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 linesmodified:History.md+1 added
5 unmodified lines6 * `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.63813 unmodified lines