fix: handle bracket notation arrays (#2178)

Co-authored-by: David Nguyen <davidngu28@gmail.com>
This commit is contained in:
Lucas Smith
2025-11-12 16:38:06 +11:00
committed by GitHub
parent 378dd605b9
commit 68a3608aee
43 changed files with 137 additions and 68 deletions

View File

@ -24,11 +24,17 @@ const getMultipartBody = async (req: Request) => {
const data: Record<string, unknown> = {};
for (const key of formData.keys()) {
const values = formData.getAll(key);
for (const [key, value] of formData.entries()) {
// !: Handles cases where our generated SDKs send key[] syntax for arrays.
const normalizedKey = key.endsWith('[]') ? key.slice(0, -2) : key;
// Return array for multiple values, single value otherwise (matches URL-encoded behavior)
data[key] = values.length > 1 ? values : values[0];
if (data[normalizedKey] === undefined) {
data[normalizedKey] = value;
} else if (Array.isArray(data[normalizedKey])) {
data[normalizedKey].push(value);
} else {
data[normalizedKey] = [data[normalizedKey], value];
}
}
return data;