Skip to content

Commit 1fa626d

Browse files
nekrasofttunnckoCore
authored andcommitted
Array parameters support (#380)
* Array parameters support * Shorter version of array syntax checking, no hasOwnProperty using
1 parent a514f6c commit 1fa626d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/incoming_form.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,19 @@ IncomingForm.prototype.parse = function(req, cb) {
8484
var fields = {}, files = {};
8585
this
8686
.on('field', function(name, value) {
87-
fields[name] = value;
87+
if (name.slice(-2) === '[]') {
88+
var realName = name.slice(0, name.length - 2);
89+
if (realName in fields) {
90+
if (!Array.isArray(fields[realName])) {
91+
fields[realName] = [fields[realName]];
92+
}
93+
} else {
94+
fields[realName] = [];
95+
}
96+
fields[realName].push(value);
97+
} else {
98+
fields[name] = value;
99+
}
88100
})
89101
.on('file', function(name, file) {
90102
if (this.multiples) {

0 commit comments

Comments
 (0)