mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
According to RFC 2046, the BNF of the form data body is:
multipart-body := [preamble CRLF]
dash-boundary transport-padding CRLF
body-part *encapsulation
close-delimiter transport-padding
[CRLF epilogue]
Where "epilogue" is any text that "may be ignored or discarded". So we
should stop parsing the body once we encounter the terminating delimiter
("--").
Note that our parsing function is from an attempt to standardize the
grammar in the spec: https://andreubotella.github.io/multipart-form-data
This proposal hasn't been updated in ~4 years, and the fetch spec still
does not have a formal definition of the body string.
37 lines
1003 B
HTML
37 lines
1003 B
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<script>
|
|
let testID = 0;
|
|
|
|
const runTest = async terminator => {
|
|
const boundary = "AaB03x";
|
|
const body =
|
|
`--${boundary}\r\n` +
|
|
'Content-Disposition: form-data; name="field"\r\n' +
|
|
"\r\n" +
|
|
`value${testID++}\r\n` +
|
|
`--${boundary}--\r\n` +
|
|
terminator;
|
|
|
|
const response = new Response(
|
|
new Blob([body], { type: `multipart/form-data; boundary=${boundary}` }),
|
|
{
|
|
headers: { "Content-Type": `multipart/form-data; boundary=${boundary}` },
|
|
}
|
|
);
|
|
|
|
const data = await response.formData();
|
|
println(`Data: ${data.get("field")}`);
|
|
};
|
|
|
|
asyncTest(async done => {
|
|
await runTest("");
|
|
await runTest("\r");
|
|
await runTest("\n");
|
|
await runTest("\r\n");
|
|
await runTest("junk");
|
|
await runTest("\r\njunk");
|
|
done();
|
|
});
|
|
</script>
|