Skip to content

Commit f77dd9e

Browse files
fix bug on exports.DemoData(). fix makes the demo usable.
1 parent 105d485 commit f77dd9e

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

multipart.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ exports.Parse = function(multipartBodyBuffer,boundary){
5353
var prevByte = i > 0 ? multipartBodyBuffer[i-1] : null;
5454
var newLineDetected = ((oneByte == 0x0a) && (prevByte == 0x0d)) ? true : false;
5555
var newLineChar = ((oneByte == 0x0a) || (oneByte == 0x0d)) ? true : false;
56-
56+
5757
if(!newLineChar)
5858
lastline += String.fromCharCode(oneByte);
59-
60-
//console.log('ST='+state,'LN='+lastline,'BF='+JSON.stringify(buffer));
6159

6260
if((0 == state) && newLineDetected){
6361
if(("--"+boundary) == lastline){
@@ -82,16 +80,9 @@ exports.Parse = function(multipartBodyBuffer,boundary){
8280
}else
8381
if(4 == state){
8482
if(lastline.length > (boundary.length+4)) lastline=''; // mem save
85-
if((("--"+boundary+"--") == lastline)){
86-
var j = buffer.length - lastline.length;
87-
var part = new Buffer(buffer.slice(0,j-1));
88-
var p = { header : header , info : info , part : part };
89-
allParts.push(process(p));
90-
break;
91-
}else
92-
if((("--"+boundary) == lastline)){
83+
if(((("--"+boundary) == lastline))){
9384
var j = buffer.length - lastline.length;
94-
var part = new Buffer(buffer.slice(0,j-1));
85+
var part = buffer.slice(0,j-1);
9586
var p = { header : header , info : info , part : part };
9687
allParts.push(process(p));
9788
buffer = []; lastline=''; state=5; header=''; info='';
@@ -127,20 +118,21 @@ exports.getBoundary = function(header){
127118
exports.DemoData = function(){
128119
body = "trash1\r\n"
129120
body += "------WebKitFormBoundaryvef1fLxmoUdYZWXp\r\n";
130-
body += "header1\r\n";
131-
body += "info1\r\n";
121+
body += "Content-Disposition: form-data; name=\"uploads[]\"; filename=\"A.txt\"\r\n";
122+
body += "Content-Type: text/plain\r\n",
132123
body += "\r\n\r\n";
133-
body += "111X";
124+
body += "@11X";
134125
body += "111Y\r\n";
135-
body += "111Z\rCCCC\nCCCC\r\nCCCCCX\r\n";
126+
body += "111Z\rCCCC\nCCCC\r\nCCCCC@\r\n\r\n";
136127
body += "------WebKitFormBoundaryvef1fLxmoUdYZWXp\r\n";
137-
body += "header2\r\n";
138-
body += "info2\r\n";
128+
body += "Content-Disposition: form-data; name=\"uploads[]\"; filename=\"B.txt\"\r\n";
129+
body += "Content-Type: text/plain\r\n",
139130
body += "\r\n\r\n";
140-
body += "222X";
131+
body += "@22X";
141132
body += "222Y\r\n";
142-
body += "222Z\r222W\n2220\r\n666X\r\n";
133+
body += "222Z\r222W\n2220\r\n666@\r\n";
143134
body += "------WebKitFormBoundaryvef1fLxmoUdYZWXp--\r\n";
144-
return body;
135+
return (new Buffer(body,'utf-8'));
136+
// returns a Buffered payload, so the it will be treated as a binary content.
145137
};
146138

0 commit comments

Comments
 (0)