Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for fieldNameSize #59

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
*.DS_Store
9 changes: 5 additions & 4 deletions lib/types/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// * support 1 nested multipart level
// (see second multipart example here:
// http://www.w3.org/TR/html401/interact/forms.html#didx-multipartform-data)
// * support limits.fieldNameSize
// -- this will require modifications to utils.parseParams

var ReadableStream = require('stream').Readable || require('readable-stream'),
inherits = require('util').inherits;
Expand Down Expand Up @@ -71,7 +69,10 @@ function Multipart(boy, cfg) {
: Infinity),
partsLimit = (limits && typeof limits.parts === 'number'
? limits.parts
: Infinity);
: Infinity),
fieldNameSizeLimit = (limits && typeof limits.fieldNameSize === 'number'
? limits.fieldNameSize
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alignment is off here

: 100);

var nfiles = 0,
nfields = 0,
Expand Down Expand Up @@ -149,7 +150,7 @@ function Multipart(boy, cfg) {
charset = defCharset;

if (header['content-disposition']) {
parsed = parseParams(header['content-disposition'][0]);
parsed = parseParams(header['content-disposition'][0], fieldNameSizeLimit);
if (!RE_FIELD.test(parsed[0]))
return skipPart(part);
for (i = 0, len = parsed.length; i < len; ++i) {
Expand Down
9 changes: 7 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var RE_ENCODED = /%([a-fA-F0-9]{2})/g;
function encodedReplacer(match, byte) {
return String.fromCharCode(parseInt(byte, 16));
}
function parseParams(str) {
function parseParams(str,fieldNameSize) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space after the comma

var res = [],
state = 'key',
charset = '',
Expand Down Expand Up @@ -73,7 +73,12 @@ function parseParams(str) {
} else if (!inquote && (str[i] === ' ' || str[i] === '\t'))
continue;
}
tmp += str[i];

if (state !== 'value' || fieldNameSize === undefined) {
tmp += str[i];
} else if ( tmp.length < fieldNameSize ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be combined with the other two conditions above this? Also the curly braces are dropped for single line blocks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, line 79 could be combined with 77. I had a console.log checks writing out characters here to verify I wasn't truncating the wrong fields. Yes, I can drop the curly braces too.

tmp += str[i];
}
}
if (charset && tmp.length) {
tmp = decodeText(tmp.replace(RE_ENCODED, encodedReplacer),
Expand Down
34 changes: 34 additions & 0 deletions test/test-types-multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,40 @@ var tests = [
],
what: 'Empty content-type and empty content-disposition'
},
{ source: [
['-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
'Content-Disposition: form-data; name="file_name_0"',
'',
'super alpha file',
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
'Content-Disposition: form-data; name="file_name_1"',
'',
'super beta file',
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
'Content-Disposition: form-data; name="upload_file_0"; filename="1k_a.dat"',
'Content-Type: application/octet-stream',
'',
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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ieldNameSize: 5
},
expected: [
['field', 'file_', 'super alpha file', false, false],
['field', 'file_', 'super beta file', false, false],
['file', 'uploa', 1023, 0, '1k_a.', '7bit', 'application/octet-stream'],
['file', 'uploa', 1023, 0, '1k_b.', '7bit', 'application/octet-stream']
],
what: 'Fields and files (limits: 5 byte field name size)'
},
];

function next() {
Expand Down