Skip to content
Myr

Added parseParam() support for name[] etc. Closes #180

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

PS. this is awesome! because now with WebKit (and opera?) you can have <input type="file" name="images[]" multiple />

authored by visionmedia · committed by visionmedia · parent 604c359 · Browse files · 2 files+36 added−8 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+36 added−8 removed

  • tests:+15 added−6 removed
  • other:+21 added−2 removed

2 files+36 added−8 removed

modified:lib/express/utils.js+21 added-2 removed
modified:spec/spec.utils.js+15 added-6 removed
86 unmodified lines
87 end88 end89 90 describe 'key[]'91 describe 'with a single value'92 it 'should still be an array'93 params = {}94 utils.mergeParam('images[]', '1', params)95 params.images.should.eql ['1']96 end97 end98 99 describe 'with empty params'100 it 'should merge correctly'101 params = {}94 utils.mergeParam('images[]', 1, params)95 params.images.should.eql [1]102 utils.mergeParam('images[]', '1', params)103 utils.mergeParam('images[]', '2', params)104 params.images.should.eql ['1', '2']105 end106 end107 108 describe 'with populated params'109 it 'should convert to an array'110 params = { images: 'foo.png'}102 utils.mergeParam('images[]', 1, params)103 params.images.should.eql ['foo.png', 1]111 utils.mergeParam('images[]', '1', params)112 params.images.should.eql ['foo.png', '1']113 end114 end115 116 describe 'with several merges'
1 unmodified line
118 params = {}119 utils.mergeParam('images[]', '1', params)120 utils.mergeParam('images[]', '2', params)121 utils.mergeParam('images[]', '3', params)113 params.images.should.eql [1,2,3]122 params.images.should.eql ['1', '2', '3']123 end124 end125 126 describe 'when nested'
1 unmodified line
128 params = {}129 utils.mergeParam('user[tj][images][]', '1', params)130 utils.mergeParam('user[tj][images][]', '2', params)131 utils.mergeParam('user[tj][images][]', '3', params)123 params.user.should.eql { tj: { images: [1,2,3] }}132 params.user.should.eql { tj: { images: ['1', '2', '3'] }}133 end134 end135 end136
2 unmodified lines