Skip to content

Commit 1c48c24

Browse files
committed
add test for handling fake boundaries
1 parent 7759ad2 commit 1c48c24

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/Multipart.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,33 @@ describe("Multipart", function () {
159159
expect(part3.headers.get("x-foo")).to.equal("Foo");
160160
expect(new TextDecoder().decode(part3.body)).to.equal("The boundary delimiter of this part has trailing SP and tab.");
161161
});
162+
163+
it("should handle strings that look like part boundary", function () {
164+
const string =
165+
'--simple boundary\r\n' +
166+
'X-Foo: Bar\r\n' +
167+
'\r\n' +
168+
'Can this handle\r\n' +
169+
'--simple boundary this is fake\r\n' +
170+
'\r\n' +
171+
'not new part\r\n' +
172+
'--simple boundary\r\n' +
173+
'X-Foo: Baz\r\n' +
174+
'\r\n' +
175+
'Final part\r\n' +
176+
'--simple boundary--\r\n'
177+
178+
const parsedMultipart = Multipart.parseBody(new TextEncoder().encode(string), new TextEncoder().encode("simple boundary"));
179+
180+
expect(parsedMultipart).to.be.an.instanceof(Multipart);
181+
expect(parsedMultipart.parts.length).to.equal(2);
182+
const part1 = parsedMultipart.parts[0];
183+
expect(part1.headers.get("x-foo")).to.equal("Bar");
184+
expect(new TextDecoder().decode(part1.body)).to.equal("Can this handle\r\n--simple boundary this is fake\r\n\r\nnot new part");
185+
const part2 = parsedMultipart.parts[1];
186+
expect(part2.headers.get("x-foo")).to.equal("Baz");
187+
expect(new TextDecoder().decode(part2.body)).to.equal("Final part");
188+
});
162189
});
163190

164191
describe("formData", function () {

0 commit comments

Comments
 (0)