Permalink
Browse files

Merge pull request #14 from hflw/master

Fixed bug where passing in invalid data would throw errors instead of passing them through next()
  • Loading branch information...
2 parents 923b260 + 8fedbb1 commit 3ae02ca237ac3da10bf5ad257a8e688f0532871e @chjj committed Jan 29, 2015
Showing with 8 additions and 3 deletions.
  1. +1 −1 lib/json.js
  2. +7 −2 lib/multipart.js
View
@@ -382,10 +382,10 @@ Parser.prototype._unexpected = function(tok) {
};
Parser.prototype._error = function(err) {
- this.destroy();
this.emit('error', typeof err === 'string'
? new Error(err)
: err);
+ this.destroy();
};
Parser.prototype.destroy = function(err) {
View
@@ -37,9 +37,10 @@ var Parser = function(type, options) {
this.options = options || {};
+ this.invalidBoundary = false;
var key = grab(type, 'boundary');
if (!key) {
- return this._error('No boundary key found.');
+ this.invalidBoundary = true;
}
this.key = new Buffer('\r\n--' + key);
@@ -50,6 +51,7 @@ var Parser = function(type, options) {
}, this);
this.state = 'start';
+ this.checkedBoundary = false;
this.pending = 0;
this.written = 0;
this.writtenDisk = 0;
@@ -71,6 +73,9 @@ Parser.prototype.write = function(data) {
if (!this.writable
|| this.epilogue) return;
+ if (this.invalidBoundary)
+ return this._error('No boundary key found.');
+
try {
this._parse(data);
} catch (e) {
@@ -312,10 +317,10 @@ Parser.prototype._reset = function() {
};
Parser.prototype._error = function(err) {
- this.destroy();
this.emit('error', typeof err === 'string'
? new Error(err)
: err);
+ this.destroy();
};
Parser.prototype.destroy = function(err) {

0 comments on commit 3ae02ca

Please sign in to comment.