Skip to content

Commit 0cf1bfe

Browse files
committed
empty part tests for Multipart
1 parent 1c48c24 commit 0cf1bfe

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/Multipart.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,29 @@ describe("Multipart", function () {
129129
expect(parsedMultipart.parts).to.be.empty;
130130
});
131131

132+
it("should parse Multipart from empty Component bytes", function () {
133+
const multipart = new Multipart([new Component({})]);
134+
const multipartBytes = multipart.bytes();
135+
const parsedMultipart = Multipart.parse(multipartBytes);
136+
expect(parsedMultipart).to.be.an.instanceof(Multipart);
137+
expect(parsedMultipart.parts.length).to.equal(1);
138+
expect(new TextDecoder().decode(parsedMultipart.parts[0].bytes())).to.equal("\r\n");
139+
});
140+
141+
it("should handle parsing of empty parts in multipart MIME string", function () {
142+
const string = "Content-type: multipart/mixed; boundary=\"simple boundary\"\r\n\r\n"
143+
+ "--simple boundary\r\n"
144+
+ "\r\n"
145+
+ "\r\n"
146+
+ "--simple boundary--\r\n";
147+
const multipart = Multipart.parse(new TextEncoder().encode(string));
148+
const multipartBytes = multipart.bytes();
149+
const parsedMultipart = Multipart.parse(multipartBytes);
150+
expect(parsedMultipart).to.be.an.instanceof(Multipart);
151+
expect(parsedMultipart.parts.length).to.equal(1);
152+
expect(new TextDecoder().decode(parsedMultipart.parts[0].bytes())).to.equal("\r\n");
153+
});
154+
132155
it("should ignore linear whitespace after boundary delimiter", function () {
133156
const string =
134157
'--simple boundary \r\n' +

0 commit comments

Comments
 (0)