Skip to content
Myr

Utilizing nodes parseQuery() util. Closes #123

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

Introduces a failing Request#param() spec, yet to be fixed.

authored by visionmedia · committed by visionmedia · parent 9a2178d · Browse files · 5 files+8 added−88 removed
This commit

State

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

Diff stats

5 files+8 added−88 removed

  • tests:+2 added−28 removed
  • other:+6 added−60 removed

5 files+8 added−88 removed

modified:lib/express/plugins/body-decoder.js+3 added-1 removed
modified:lib/express/helpers.js+1 added-58 removed
modified:lib/express/request.js+2 added-1 removed
5 unmodified lines
6 */78var StaticFile = require('express/static').File,9 statusBodies = require('http').STATUS_CODES,10 queryString = require('querystring'),11 url = require('url')1213// --- InvalidStatusCode14
52 unmodified lines
67 this.response = response68 this.url = url.parse(this.url)69 this.url.pathname = exports.normalizePath(this.url.pathname)70 this.params = { 70 get: parseParams(this.url.query) || {}, 71 get: this.url.query ? queryString.parseQuery(this.url.query) : {}, 72 post: {}, 73 path: {}74 }75 this.plugins = $(Express.plugins).map(function(plugin){
189 unmodified lines
modified:spec/spec.helpers.js-27 removed
12describe 'Express'3 describe 'parseParams()'4 it 'should parse simple query string key / value pairs'5 parseParams('foo=bar').should.eql { foo: 'bar' }6 parseParams('foo=bar&baz=1').should.eql { foo: 'bar', baz: '1' }7 end8 9 it 'should parse named nested params'10 var user = { user: { name: 'tj', email: 'tj@vision-media.ca' }}11 parseParams('user[name]=tj&user[email]=tj@vision-media.ca').should.eql user12 end13 14 it 'should parse several levels of nesting'15 var user = { user: { name: 'tj', email: { primary: 'tj@vision-media.ca' }}}16 parseParams('user[name]=tj&user[email][primary]=tj@vision-media.ca').should.eql user17 end18 19 it 'should convert + to literal space'20 parseParams('foo=bar+baz++that').should.eql { foo: 'bar baz that' }21 parseParams('user[name]=tj+holowaychuk').should.eql { user: { name: 'tj holowaychuk' }}22 end23 24 it 'should decode hex literals'25 parseParams('foo=bar%20baz%20%20that').should.eql { foo: 'bar baz that' }26 parseParams('user[name]=tj%20holowaychuk').should.eql { user: { name: 'tj holowaychuk' }}27 end28 end29 3 describe 'toArray()'4 describe 'when given an array'5 it 'should return the array'6 toArray([1,2,3]).should.eql [1,2,3]
42 unmodified lines
modified:spec/spec.request.js+2 added-1 removed
152 unmodified lines
153 get('/user/12').body.should.eql '12'154 get('/product/ipod').body.should.eql 'ipod'155 end156157 it 'should access request.url.params'157 it 'should work with a query string'158 get('/user', function(){159 return this.param('page') || 'First page'160 })161 get('/user').body.should.eql 'First page'162 get('/user?page=2').body.should.eql '2'163 get('/user?foo[]=bar&page=5').body.should.eql '5'164 end165166 it 'should work with splats'167 get('/:path/*.*', function(path, file, ext){
7 unmodified lines