Skip to content

Commit

Permalink
Merge pull request #224 from egirshov/issue-162
Browse files Browse the repository at this point in the history
parse empty form data
  • Loading branch information
svnlto committed May 18, 2013
2 parents dda6abd + d8b60b2 commit 92e0854
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/multipart_parser.js
Expand Up @@ -127,18 +127,25 @@ MultipartParser.prototype.write = function(buffer) {
state = S.START_BOUNDARY;
case S.START_BOUNDARY:
if (index == boundary.length - 2) {
if (c != CR) {
if (c == HYPHEN) {
flags |= F.LAST_BOUNDARY;
} else if (c != CR) {
return i;
}
index++;
break;
} else if (index - 1 == boundary.length - 2) {
if (c != LF) {
if (flags & F.LAST_BOUNDARY && c == HYPHEN){
callback('end');
state = S.END;
flags = 0;
} else if (!(flags & F.LAST_BOUNDARY) && c == LF) {
index = 0;
callback('partBegin');
state = S.HEADER_FIELD_START;
} else {
return i;
}
index = 0;
callback('partBegin');
state = S.HEADER_FIELD_START;
break;
}

Expand Down Expand Up @@ -260,6 +267,7 @@ MultipartParser.prototype.write = function(buffer) {
callback('partEnd');
callback('end');
state = S.END;
flags = 0;
} else {
index = 0;
}
Expand Down
6 changes: 6 additions & 0 deletions test/fixture/http/misc/empty-multipart2.http
@@ -0,0 +1,6 @@
POST /upload HTTP/1.1
Host: localhost:8080
Content-Type: multipart/form-data; boundary=----TLV0SrKD4z1TRxRhAPUvZ
Content-Length: 31

------TLV0SrKD4z1TRxRhAPUvZ--
1 change: 1 addition & 0 deletions test/fixture/js/misc.js
Expand Up @@ -2,5 +2,6 @@ module.exports = {
'empty.http': [],
'empty-urlencoded.http': [],
'empty-multipart.http': [],
'empty-multipart2.http': [],
'minimal.http': [],
};

0 comments on commit 92e0854

Please sign in to comment.