mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 00:19:48 +01:00
Fix infinite loop condition using mergeParams: true
This commit is contained in:
parent
97b2d70d8a
commit
ee90042d0c
|
|
@ -1,3 +1,8 @@
|
|||
unreleased
|
||||
==========
|
||||
|
||||
* Fix infinite loop condition using `mergeParams: true`
|
||||
|
||||
4.13.2 / 2015-07-31
|
||||
===================
|
||||
|
||||
|
|
|
|||
|
|
@ -578,9 +578,12 @@ function mergeParams(params, parent) {
|
|||
var o = 0;
|
||||
|
||||
// determine numeric gaps
|
||||
while (i === o || o in parent) {
|
||||
if (i in params) i++;
|
||||
if (o in parent) o++;
|
||||
while (i in params) {
|
||||
i++;
|
||||
}
|
||||
|
||||
while (o in parent) {
|
||||
o++;
|
||||
}
|
||||
|
||||
// offset numeric indices in params before merge
|
||||
|
|
|
|||
|
|
@ -320,6 +320,22 @@ describe('app.router', function(){
|
|||
.expect(200, '[["0","10"],["1","tj"],["2","profile"]]', done);
|
||||
})
|
||||
|
||||
it('should merge numeric indices req.params when parent has same number', function(done){
|
||||
var app = express();
|
||||
var router = new express.Router({ mergeParams: true });
|
||||
|
||||
router.get('/name:(\\w+)', function(req, res){
|
||||
var keys = Object.keys(req.params).sort();
|
||||
res.send(keys.map(function(k){ return [k, req.params[k]] }));
|
||||
});
|
||||
|
||||
app.use('/user/id:(\\d+)', router);
|
||||
|
||||
request(app)
|
||||
.get('/user/id:10/name:tj')
|
||||
.expect(200, '[["0","10"],["1","tj"]]', done);
|
||||
})
|
||||
|
||||
it('should ignore invalid incoming req.params', function(done){
|
||||
var app = express();
|
||||
var router = new express.Router({ mergeParams: true });
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user