Skip to content

Commit

Permalink
fix: single field when allowFieldsDuplication enabled (#3981)
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 authored Jul 26, 2024
1 parent 7deef22 commit 8987aba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/upload/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ const headSeparator = Buffer.from('\r\n\r\n');
function saveFields(fields, key, value, allowFieldsDuplication) {
if (allowFieldsDuplication) {
if (!fields[key]) {
fields[key] = [value];
fields[key] = value;
} else {
if (!Array.isArray(fields[key])) {
fields[key] = [fields[key]];
}
fields[key].push(value);
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions packages/upload/test/koa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,14 @@ describe('test/koa.test.ts', function () {
await request.post('/upload')
.field('name', 'form')
.field('name', 'form2')
.field('nameOther', 'other')
.attach('file', filePath)
.expect(200)
.then(async response => {
assert(response.body.files.length === 1);
assert(response.body.files[0].filename === 'test.pdf');
assert(JSON.stringify(response.body.fields.name) === JSON.stringify(['form', 'form2']));
assert(response.body.fields.nameOther === 'other');
});
});
});
Expand Down

0 comments on commit 8987aba

Please sign in to comment.