Skip to content

Commit

Permalink
Support file input as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kidylee committed Jan 8, 2025
1 parent 6b3dcf6 commit d835984
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/types/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class Multipart extends Writable {

if (disp.params['filename*'])
filename = disp.params['filename*'];
else if (disp.params.filename)
else if (disp.params.filename !== undefined)
filename = disp.params.filename;

if (filename !== undefined && !preservePath)
Expand Down
26 changes: 26 additions & 0 deletions test/test-types-multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,32 @@ const tests = [
],
what: 'Empty part'
},
{ source: [
['-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
'Content-Disposition: form-data; '
+ 'name="upload_file_0"; filename=""',
'Content-Type: application/octet-stream',
'',
'',
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k--',
].join('\r\n')
],
boundary: '---------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
expected: [
{ type: 'file',
name: 'upload_file_0',
data: new Buffer.from(''),
info: {
filename: '',
encoding: '7bit',
mimeType: 'application/octet-stream',
},
limited: false,
}
],
events: ['file'],
what: 'Optional file'
}
];

for (const test of tests) {
Expand Down

0 comments on commit d835984

Please sign in to comment.