Skip to content
Myr

Fixed req.param() bug returning Array.prototype methods. Closes #552

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

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 64da262 · Browse files · 2 files+12 added−4 removed
This commit

State

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

Diff stats

2 files+12 added−4 removed

  • tests:+9 added−1 removed
  • other:+3 added−3 removed

2 files+12 added−4 removed

modified:lib/request.js+3 added-3 removed
138 unmodified lines
139 */140141req.param = function(name, defaultValue){142 // route params like /user/:id143 if (this.params[name] !== undefined) {143 if (this.params.hasOwnProperty(name) && undefined !== this.params[name]) {144 return this.params[name]; 145 }146 // query string params147 if (this.query[name] !== undefined) {147 if (undefined !== this.query[name]) {148 return this.query[name]; 149 }150 // request body params via connect.bodyParser151 if (this.body && this.body[name] !== undefined) {151 if (this.body && undefined !== this.body[name]) {152 return this.body[name];153 }154 return defaultValue;155};
133 unmodified lines
modified:test/request.test.js+9 added-1 removed
100 unmodified lines
101 102 app.post('/user', function(req, res){103 res.send('user ' + req.param('id'));104 });105 105106 app.get('/:sort', function(req, res){107 res.send('sort ' + req.param('sort'));108 });109110 assert.response(app,111 { url: '/asc' },112 { body: 'sort asc' });113114 assert.response(app,115 { url: '/user/12' },116 { body: 'user 12' });117 118 assert.response(app,
189 unmodified lines