Skip to content
Myr

Fix persistence of req.params from app.params

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

fixes #2170

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 7df7f7a · Browse files · 3 files+43 added−7 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+43 added−7 removed

  • tests:+20 added−0 removed
  • other:+23 added−7 removed

3 files+43 added−7 removed

modified:lib/router/index.js+22 added-7 removed
318 unmodified lines
319 return param();320 }321322 // param previously called with same value or error occurred323 if (paramCalled && (paramCalled.err || paramCalled.val === paramVal)) {324 return param(paramCalled.err);323 if (paramCalled && (paramCalled.error || paramCalled.match === paramVal)) {324 // restore value325 req.params[name] = paramCalled.value;326327 // next param328 return param(paramCalled.error);329 }330327 called[name] = paramCalled = { val: paramVal };331 called[name] = paramCalled = {332 error: null,333 match: paramVal,334 value: paramVal335 };336337 try {338 return paramCallback();339 } catch (err) {
2 unmodified lines
342 }343344 // single param callbacks345 function paramCallback(err) {338 if (err && paramCalled) {346 var fn = paramCallbacks[paramIndex++];347348 // store updated value349 paramCalled.value = req.params[key.name];350351 if (err) {352 // store error340 paramCalled.err = err;353 paramCalled.error = err;354 param(err);355 return;356 }357343 var fn = paramCallbacks[paramIndex++];344 if (err || !fn) return param(err);358 if (!fn) return param();359360 fn(req, res, paramCallback, paramVal, key.name);361 }362363 param();
87 unmodified lines
modified:test/app.param.js+20 added
155 unmodified lines
156 .get('/foo/bob')157 .expect('2 2 foo,bob', done);158 })159160 it('should support altering req.params across routes', function(done) {161 var app = express();162163 app.param('user', function(req, res, next, user) {164 req.params.user = 'loki';165 next();166 });167168 app.get('/:user', function(req, res, next) {169 next('route');170 });171 app.get('/:user', function(req, res, next) {172 res.send(req.params.user);173 });174175 request(app)176 .get('/bob')177 .expect('loki', done);178 })179180 it('should work with encoded values', function(done){181 var app = express();182183 app.param('name', function(req, res, next, name){
78 unmodified lines
modified:History.md+1 added
1unreleased2==========34 * fix persistence of modified `req.params[name]` from `app.param()`5 * deps: debug@1.0.2674.4.2 / 2014-06-098==================
1601 unmodified lines