Skip to content
Myr

Fix infinite loop condition using mergeParams: true

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

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

  • tests:+16 added−0 removed
  • other:+11 added−3 removed

3 files+27 added−3 removed

modified:lib/router/index.js+6 added-3 removed
576 unmodified lines
577 var i = 0;578 var o = 0;579580 // determine numeric gaps581 while (i === o || o in parent) {582 if (i in params) i++;583 if (o in parent) o++;581 while (i in params) {582 i++;583 }584585 while (o in parent) {586 o++;587 }588589 // offset numeric indices in params before merge590 for (i--; i >= 0; i--) {591 params[i + o] = params[i];592
53 unmodified lines
modified:test/app.router.js+16 added
318 unmodified lines
319 .get('/user/id:10/name:tj/profile')320 .expect(200, '[["0","10"],["1","tj"],["2","profile"]]', done);321 })322323 it('should merge numeric indices req.params when parent has same number', function(done){324 var app = express();325 var router = new express.Router({ mergeParams: true });326327 router.get('/name:(\\w+)', function(req, res){328 var keys = Object.keys(req.params).sort();329 res.send(keys.map(function(k){ return [k, req.params[k]] }));330 });331332 app.use('/user/id:(\\d+)', router);333334 request(app)335 .get('/user/id:10/name:tj')336 .expect(200, '[["0","10"],["1","tj"]]', done);337 })338339 it('should ignore invalid incoming req.params', function(done){340 var app = express();341 var router = new express.Router({ mergeParams: true });342
672 unmodified lines
modified:History.md+5 added
1unreleased2==========34 * Fix infinite loop condition using `mergeParams: true`564.13.2 / 2015-07-317===================89 * deps: accepts@~1.2.12
3015 unmodified lines