Skip to content

Commit

Permalink
Merge pull request #190 from egirshov/missing-hyphens
Browse files Browse the repository at this point in the history
tolerate incorrect last boundary
  • Loading branch information
svnlto committed Jan 31, 2013
2 parents 2e7876a + a09e777 commit 7f52318
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/multipart_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,17 @@ MultipartParser.prototype.write = function(buffer) {
};

MultipartParser.prototype.end = function() {
if (this.state != S.END) {
var callback = function(self, name) {
var callbackSymbol = 'on'+name.substr(0, 1).toUpperCase()+name.substr(1);
if (callbackSymbol in self) {
self[callbackSymbol]();
}
};
if ((this.state == S.HEADER_FIELD_START && this.index == 0) ||
(this.state == S.PART_DATA && this.index == this.boundary.length)) {
callback(this, 'partEnd');
callback(this, 'end');
} else if (this.state != S.END) {
return new Error('MultipartParser.end(): stream ended unexpectedly: ' + this.explain());
}
};
Expand Down
12 changes: 12 additions & 0 deletions test/fixture/http/workarounds/missing-hyphens1.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
POST /upload HTTP/1.1
Host: localhost:8080
Content-Type: multipart/form-data; boundary=----TLV0SrKD4z1TRxRhAPUvZ
Content-Length: 178

------TLV0SrKD4z1TRxRhAPUvZ
Content-Disposition: form-data; name="upload"; filename="plain.txt"
Content-Type: text/plain

I am a plain text file

------TLV0SrKD4z1TRxRhAPUvZ
12 changes: 12 additions & 0 deletions test/fixture/http/workarounds/missing-hyphens2.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
POST /upload HTTP/1.1
Host: localhost:8080
Content-Type: multipart/form-data; boundary=----TLV0SrKD4z1TRxRhAPUvZ
Content-Length: 180

------TLV0SrKD4z1TRxRhAPUvZ
Content-Disposition: form-data; name="upload"; filename="plain.txt"
Content-Type: text/plain

I am a plain text file

------TLV0SrKD4z1TRxRhAPUvZ
6 changes: 6 additions & 0 deletions test/fixture/js/workarounds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports['missing-hyphens1.http'] = [
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt'},
];
module.exports['missing-hyphens2.http'] = [
{type: 'file', name: 'upload', filename: 'plain.txt', fixture: 'plain.txt'},
];

0 comments on commit 7f52318

Please sign in to comment.