Skip to content

Commit

Permalink
Fixes mscdex#297
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Peabody committed Aug 25, 2022
1 parent 9aadb7a commit 6aa72c7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/types/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ retrydata:
}

fileSize += chunk.length;
if (fileSize === fileSizeLimit) {
if (fileSize === fileSizeLimit && chunk.length < (end - start)) {
if (chunk.length > 0)
this._fileStream.push(chunk);
this._fileStream.emit('limit');
Expand All @@ -499,7 +499,7 @@ retrydata:

fieldSize += actualLen;
field.push(chunk);
if (fieldSize === fieldSizeLimit) {
if (fieldSize === fieldSizeLimit && chunk.length < (end - start)) {
skipPart = true;
partTruncated = true;
}
Expand Down
43 changes: 43 additions & 0 deletions test/test-types-multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,49 @@ const tests = [
],
what: 'Fields and files (limits)'
},
{ source: [
['-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
'Content-Disposition: form-data; name="file_name_0"',
'',
'super alpha file',
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
'Content-Disposition: form-data; '
+ 'name="upload_file_0"; filename="1k_a.dat"',
'Content-Type: application/octet-stream',
'',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k--'
].join('\r\n')
],
boundary: '---------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
limits: {
fileSize: 26,
fieldSize: 16
},
expected: [
{ type: 'field',
name: 'file_name_0',
val: 'super alpha file',
info: {
nameTruncated: false,
valueTruncated: false,
encoding: '7bit',
mimeType: 'text/plain',
},
},
{ type: 'file',
name: 'upload_file_0',
data: Buffer.from('ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
info: {
filename: '1k_a.dat',
encoding: '7bit',
mimeType: 'application/octet-stream',
},
limited: false
},
],
what: 'Fields and files (exact limits)'
},
{ source: [
['-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
'Content-Disposition: form-data; name="file_name_0"',
Expand Down

0 comments on commit 6aa72c7

Please sign in to comment.