Skip to content

Commit 86ee0c5

Browse files
Merge pull request francismeynard#4 from mabarbeau/master
Add utf8 support
2 parents 4f8f92f + 87d738a commit 86ee0c5

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ const parse = (event) => new Promise((resolve, reject) => {
6060
resolve(result);
6161
});
6262

63-
busboy.write(event.body, event.isBase64Encoded ? 'base64' : 'binary');
63+
const encoding = event.encoding || (event.isBase64Encoded ? "base64" : "binary");
64+
65+
busboy.write(event.body, encoding);
6466
busboy.end();
6567
});
6668

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lambda-multipart-parser",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "This module will parse the multipart-form containing files and fields from the lambda event object.",
55
"main": "index.js",
66
"author": "francismeynard",

test/MultipartParserTest.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ describe('MultipartParser', () => {
7373
assert.equal(file.encoding, "7bit");
7474
assert.equal(file.fieldname, "uploadFile1");
7575
});
76+
77+
it('should parse the multipart form-data successfully given utf8 encoded form data', async () => {
78+
// GIVEN
79+
const html = "<p> </p>";
80+
const event = {
81+
headers: {
82+
"Content-Type": "multipart/form-data; boundary=xYzZY",
83+
},
84+
body: `--xYzZY\r\nContent-Disposition: form-data; name="html"\r\n\r\n${html}\r\n--xYzZY--\r\n`,
85+
encoding: 'utf8',
86+
};
87+
88+
// WHEN
89+
const result = await parser.parse(event);
90+
91+
// THEN
92+
assert.equal(html, result.html);
93+
});
94+
95+
7696

7797
});
7898

0 commit comments

Comments
 (0)