Skip to content
Myr

Fix issue where next('route') in app.param would incorrectly skip values

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

fixes #2655

authored by Radu Dan · committed by Douglas Christopher Wilson · parent 3d2ecdd · Browse files · 3 files+63 added−1 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+63 added−1 removed

  • tests:+60 added−0 removed
  • other:+3 added−1 removed

3 files+63 added−1 removed

modified:lib/router/index.js+2 added-1 removed
355 unmodified lines
356 return param();357 }358359 // param previously called with same value or error occurred360 if (paramCalled && (paramCalled.error || paramCalled.match === paramVal)) {360 if (paramCalled && (paramCalled.match === paramVal361 || (paramCalled.error && paramCalled.error !== 'route'))) {362 // restore value363 req.params[name] = paramCalled.value;364365 // next param
266 unmodified lines
modified:test/app.param.js+60 added
301 unmodified lines
302 request(app)303 .get('/user/new')304 .expect('get.new', done);305 })306307 it('should not call when values differ on error', function(done) {308 var app = express();309 var called = 0;310 var count = 0;311312 app.param('user', function(req, res, next, user) {313 called++;314 if (user === 'foo') throw new Error('err!');315 req.user = user;316 next();317 });318319 app.get('/:user/bob', function(req, res, next) {320 count++;321 next();322 });323 app.get('/foo/:user', function(req, res, next) {324 count++;325 next();326 });327328 app.use(function(err, req, res, next) {329 res.status(500);330 res.send([count, called, err.message].join(' '));331 });332333 request(app)334 .get('/foo/bob')335 .expect(500, '0 1 err!', done)336 });337338 it('should call when values differ when using "next"', function(done) {339 var app = express();340 var called = 0;341 var count = 0;342343 app.param('user', function(req, res, next, user) {344 called++;345 if (user === 'foo') return next('route');346 req.user = user;347 next();348 });349350 app.get('/:user/bob', function(req, res, next) {351 count++;352 next();353 });354 app.get('/foo/:user', function(req, res, next) {355 count++;356 next();357 });358 app.use(function(req, res) {359 res.end([count, called, req.user].join(' '));360 });361362 request(app)363 .get('/foo/bob')364 .expect('1 2 bob', done);365 })366 })367})
modified:History.md+1 added
1unreleased2==========34 * Fix issue where `next('route')` in `app.param` would incorrectly skip values5 * deps: cookie@0.1.36 - perf: deduce the scope of try-catch deopt7 - perf: remove argument reassignments8 * deps: escape-html@1.0.2
2907 unmodified lines