larvitreqparser 0.5.40 → 0.5.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +17 -1
  2. package/package.json +1 -1
  3. package/test/test.js +33 -0
package/index.js CHANGED
@@ -143,6 +143,7 @@ ReqParser.prototype.parseFormMultipart = function parseFormMultipart(req, cb) {
143
143
  const that = this;
144
144
 
145
145
  let fieldsStr = '';
146
+ let cbCalled = false;
146
147
 
147
148
  req.formFields = {};
148
149
  req.formFiles = {};
@@ -190,6 +191,14 @@ ReqParser.prototype.parseFormMultipart = function parseFormMultipart(req, cb) {
190
191
  fieldsStr += encodeURIComponent(fieldName) + '=' + encodeURIComponent(fieldVal) + '&';
191
192
  });
192
193
 
194
+ bb.on('error', err => {
195
+ that.log.error('Error from busboy stream: ' + err.message);
196
+ if (cbCalled) return;
197
+ cbCalled = true;
198
+
199
+ return cb(err);
200
+ });
201
+
193
202
  bb.on('finish', function () {
194
203
  const tasks = [];
195
204
 
@@ -200,6 +209,9 @@ ReqParser.prototype.parseFormMultipart = function parseFormMultipart(req, cb) {
200
209
  req.formFields = qs.parse(fieldsStr, that.qsParseOptions || {});
201
210
 
202
211
  if (that.options.storage === 'memory') {
212
+ if (cbCalled) return;
213
+ cbCalled = true;
214
+
203
215
  return cb();
204
216
  }
205
217
 
@@ -224,7 +236,11 @@ ReqParser.prototype.parseFormMultipart = function parseFormMultipart(req, cb) {
224
236
  }
225
237
  }
226
238
 
227
- async.parallel(tasks, cb);
239
+ async.parallel(tasks, err => {
240
+ if (cbCalled) return;
241
+ cbCalled = true;
242
+ cb(err);
243
+ });
228
244
  });
229
245
 
230
246
  if (that.storage === 'memory') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "larvitreqparser",
3
- "version": "0.5.40",
3
+ "version": "0.5.41",
4
4
  "description": "Middleware to larvitbase or Express to handle forms",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test/test.js CHANGED
@@ -499,6 +499,39 @@ test('POST, empty form should not crasch application', t => {
499
499
  });
500
500
  });
501
501
 
502
+ test('POST, empty form with form data boundary should not crasch application (request lib can send this)', t => {
503
+ const reqParser = new ReqParser({ log });
504
+
505
+ let server;
506
+ let port;
507
+
508
+ startServer(reqParser, (req, res) => {
509
+ t.ok(req.err, 'Error response should have been sent');
510
+ t.equals(req.err.message, 'Unexpected end of form', 'Error message should be "Unexpected end of form"');
511
+
512
+ res.end();
513
+ server.close(err => {
514
+ if (err) throw err;
515
+ });
516
+
517
+ t.end();
518
+ }, (err, result) => {
519
+ if (err) throw err;
520
+
521
+ server = result;
522
+ port = server.address().port;
523
+
524
+ axios({
525
+ method: 'POST',
526
+ url: 'http://127.0.0.1:' + port + '/',
527
+ data: undefined,
528
+ headers: {
529
+ 'Content-Type': 'multipart/form-data; boundary=--------------------------284181756791521756513404',
530
+ },
531
+ });
532
+ });
533
+ });
534
+
502
535
  test('clean will remove temporary form files', t => {
503
536
  const storagePath = tmpDir + '/' + uuidLib.v4();
504
537
  const reqParser = new ReqParser({ storage: storagePath, log });