Skip to content

Commit 03de30c

Browse files
authoredApr 23, 2024··
Merge pull request #1800 from tomstrong64/master
Update formidable
2 parents 1c8338b + b9c7837 commit 03de30c

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed
 

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"debug": "^4.3.4",
2525
"fast-safe-stringify": "^2.1.1",
2626
"form-data": "^4.0.0",
27-
"formidable": "^2.1.2",
27+
"formidable": "^3.5.1",
2828
"methods": "^1.1.2",
2929
"mime": "2.6.0",
3030
"qs": "^6.11.0",
@@ -38,8 +38,8 @@
3838
"@babel/runtime": "^7.20.13",
3939
"@commitlint/cli": "17",
4040
"@commitlint/config-conventional": "17",
41-
"Base64": "^1.1.0",
4241
"babelify": "^10.0.0",
42+
"Base64": "^1.1.0",
4343
"basic-auth-connect": "^1.0.0",
4444
"body-parser": "^1.20.1",
4545
"browserify": "^17.0.0",

‎src/node/index.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ Request.prototype._pipeContinue = function (stream, options) {
469469
res.pipe(stream, options);
470470
res.once('end', () => this.emit('end'));
471471
}
472-
473472
});
474473
return stream;
475474
};
@@ -1093,7 +1092,7 @@ Request.prototype._end = function () {
10931092
parser = exports.parse.image; // It's actually a generic Buffer
10941093
buffer = true;
10951094
} else if (multipart) {
1096-
const form = formidable();
1095+
const form = formidable.formidable();
10971096
parser = form.parse.bind(form);
10981097
buffer = true;
10991098
} else if (isBinary(mime)) {
@@ -1162,6 +1161,31 @@ Request.prototype._end = function () {
11621161
}
11631162

11641163
if (parserHandlesEnd) {
1164+
if (multipart) {
1165+
// formidable v3 always returns an array with the value in it
1166+
// so we need to flatten it
1167+
if (object) {
1168+
for (const key in object) {
1169+
const value = object[key];
1170+
if (Array.isArray(value) && value.length === 1) {
1171+
object[key] = value[0];
1172+
} else {
1173+
object[key] = value;
1174+
}
1175+
}
1176+
}
1177+
1178+
if (files) {
1179+
for (const key in files) {
1180+
const value = files[key];
1181+
if (Array.isArray(value) && value.length === 1) {
1182+
files[key] = value[0];
1183+
} else {
1184+
files[key] = value;
1185+
}
1186+
}
1187+
}
1188+
}
11651189
this.emit('end');
11661190
this.callback(null, this._emitResponse(object, files));
11671191
}

0 commit comments

Comments
 (0)
Please sign in to comment.