From d835984c1b16291a7c39bcabdd411f66afa1d637 Mon Sep 17 00:00:00 2001 From: Kidy Lee Date: Wed, 8 Jan 2025 16:05:52 +0800 Subject: [PATCH] Support file input as optional --- lib/types/multipart.js | 2 +- test/test-types-multipart.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/types/multipart.js b/lib/types/multipart.js index cc0d7bb..9b1bbe0 100644 --- a/lib/types/multipart.js +++ b/lib/types/multipart.js @@ -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) diff --git a/test/test-types-multipart.js b/test/test-types-multipart.js index 9755642..c0c0776 100644 --- a/test/test-types-multipart.js +++ b/test/test-types-multipart.js @@ -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) {