Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix for some of the issues discussed in issue #33 #77

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+13 −2
Split
View
@@ -90,7 +90,16 @@ IncomingForm.prototype.parse = function(req, cb) {
var fields = {}, files = {};
this
.on('field', function(name, value) {
- fields[name] = value;
+ // check for arrays
+ if (name.indexOf("[]") === -1) { // not an array
+ fields[name] = value;
+ } else { // is an array
+ name = name.replace("[]","");
+ if (typeof fields[name] === "undefined") {
+ fields[name] = [];
+ }
+ fields[name].push(value);
+ }
})
.on('file', function(name, file) {
files[name] = file;
@@ -199,6 +199,8 @@ test(function parse() {
fn('field1', 'foo');
fn('field1', 'bar');
fn('field2', 'nice');
+ fn('fieldArray[]', 'first');
+ fn('fieldArray[]', 'second');
}
if (event == 'file') {
@@ -214,7 +216,7 @@ test(function parse() {
});
form.parse(REQ, gently.expect(function parseCbOk(err, fields, files) {
- assert.deepEqual(fields, {field1: 'bar', field2: 'nice'});
+ assert.deepEqual(fields, {field1: 'bar', field2: 'nice', fieldArray: ['first','second']});
assert.deepEqual(files, {file1: '2', file2: '3'});
}));