Skip to content

Commit 160b062

Browse files
committed
LWSP parsing test
1 parent 30a9c9f commit 160b062

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/Multipart.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,37 @@ describe("Multipart", function () {
128128
expect(parsedMultipart).to.be.an.instanceof(Multipart);
129129
expect(parsedMultipart.parts).to.be.empty;
130130
});
131+
132+
it("should ignore linear whitespace after boundary delimiter", function () {
133+
const string =
134+
'--simple boundary \r\n' +
135+
'X-Foo: Bar\r\n' +
136+
'\r\n' +
137+
'The boundary delimiter of this part has trailing SP.\r\n' +
138+
'--simple boundary\t\t\r\n' +
139+
'X-Foo: Baz\r\n' +
140+
'\r\n' +
141+
'The boundary delimiter of this part has trailing tab.\r\n' +
142+
'--simple boundary \t\t\ \r\n' +
143+
'X-Foo: Foo\r\n' +
144+
'\r\n' +
145+
'The boundary delimiter of this part has trailing SP and tab.\r\n' +
146+
'--simple boundary--\r\r\n'
147+
148+
const parsedMultipart = Multipart.parseBody(new TextEncoder().encode(string), new TextEncoder().encode("simple boundary"));
149+
150+
expect(parsedMultipart).to.be.an.instanceof(Multipart);
151+
expect(parsedMultipart.parts.length).to.equal(3);
152+
const part1 = parsedMultipart.parts[0];
153+
expect(part1.headers.get("x-foo")).to.equal("Bar");
154+
expect(new TextDecoder().decode(part1.body)).to.equal("The boundary delimiter of this part has trailing SP.");
155+
const part2 = parsedMultipart.parts[1];
156+
expect(part2.headers.get("x-foo")).to.equal("Baz");
157+
expect(new TextDecoder().decode(part2.body)).to.equal("The boundary delimiter of this part has trailing tab.");
158+
const part3 = parsedMultipart.parts[2];
159+
expect(part3.headers.get("x-foo")).to.equal("Foo");
160+
expect(new TextDecoder().decode(part3.body)).to.equal("The boundary delimiter of this part has trailing SP and tab.");
161+
});
131162
});
132163

133164
describe("formData", function () {

0 commit comments

Comments
 (0)