Skip to content

Commit

Permalink
Fix inner numeric indices incorrectly altering parent req.params
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Aug 3, 2015
1 parent ee90042 commit 11a77a3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -2,6 +2,7 @@ unreleased
==========

* Fix infinite loop condition using `mergeParams: true`
* Fix inner numeric indices incorrectly altering parent `req.params`

4.13.2 / 2015-07-31
===================
Expand Down
2 changes: 1 addition & 1 deletion lib/router/index.js
Expand Up @@ -596,7 +596,7 @@ function mergeParams(params, parent) {
}
}

return mixin(parent, params);
return mixin(obj, params);
}

// restore obj props after function
Expand Down
20 changes: 20 additions & 0 deletions test/app.router.js
Expand Up @@ -354,6 +354,26 @@ describe('app.router', function(){
.get('/user/tj')
.expect(200, '[["name","tj"]]', done);
})

it('should restore req.params', function(done){
var app = express();
var router = new express.Router({ mergeParams: true });

router.get('/user:(\\w+)/*', function (req, res, next) {
next();
});

app.use('/user/id:(\\d+)', function (req, res, next) {
router(req, res, function (err) {
var keys = Object.keys(req.params).sort();
res.send(keys.map(function(k){ return [k, req.params[k]] }));
});
});

request(app)
.get('/user/id:42/user:tj/profile')
.expect(200, '[["0","42"]]', done);
})
})

describe('trailing slashes', function(){
Expand Down

0 comments on commit 11a77a3

Please sign in to comment.