Skip to content
Myr

Fixed bug preventing falsey params. Closes #286

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

Request#param() would prevously fail with ?page=0 for example when param("page") is used since it would return undefined and not 0

authored by visionmedia · committed by visionmedia · parent 6571e19 · Browse files · 2 files+10 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

2 files+10 added−7 removed

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

2 files+10 added−7 removed

modified:lib/express/request.js+9 added-6 removed
76 unmodified lines
77 : this.response.headers[key.lowercase] = val78 },79 80 /**81 * Return a param _key_ value or null.81 * Return the param _key_ value or undefined.82 *83 * - Checks route populated path parameters84 * - Checks POST parameters83 * - Checks GET parameters84 * - Checks POST parameters85 * - Checks route populated path parameters86 *87 * @param {string} key88 * @return {string}89 * @api public90 */9192 param: function(key) {93 return this.params.get[key] ||94 this.params.post[key] ||95 this.params.path[key]93 if (key in this.params.get)94 return this.params.get[key]95 if (key in this.params.post)96 return this.params.post[key]97 if (key in this.params.path)98 return this.params.path[key]99 },100 101 /**102 * Check if Accept header includes the mime type
247 unmodified lines
modified:spec/spec.request.js+1 added-1 removed
201 unmodified lines
202203 it 'should work with a query string'204 get('/user', function(){205 var page = this.param('page')206 return page ? String(page) : 'First page'206 return page === undefined ? 'First page' : String(page)207 })208 get('/user').body.should.eql 'First page'209 get('/user?page=0').body.should.eql '0'210 get('/user?page=2').body.should.eql '2'
159 unmodified lines