forked from cloudflare/workerd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port FormData tests from internal to workerd (cloudflare#1355)
- Loading branch information
Showing
4 changed files
with
949 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
export const sendFilesInFormdata = { | ||
async test() { | ||
const INPUT = `--2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a | ||
Content-Disposition: form-data; name="foo"; filename="foo.txt" | ||
Content-Type: application/octet-stream | ||
foo-content | ||
--2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a | ||
Content-Disposition: form-data; name="bar"; filename="bar-renamed.txt" | ||
Content-Type: application/octet-stream | ||
bar1-content | ||
--2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a | ||
Content-Disposition: form-data; name="bar"; filename="bar2.txt" | ||
Content-Type: text/bary | ||
bar2-content | ||
--2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a | ||
Content-Disposition: form-data; name="baz"; filename="baz" | ||
Content-Type: text/bazzy | ||
baz-content | ||
--2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a | ||
Content-Disposition: form-data; name="qux"; filename="qux%0A%22\\.txt" | ||
Content-Type: application/octet-stream | ||
qux-content | ||
--2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a-- | ||
`; | ||
|
||
const req = new Request('https://example.org', { | ||
method: 'POST', | ||
body: INPUT, | ||
headers: { | ||
'content-type': 'multipart/form-data;boundary=2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a' | ||
} | ||
}); | ||
|
||
const form = await req.formData(); | ||
|
||
form.set("foo", new File(["foo-content"], "foo.txt")); | ||
form.append("bar", new File(["bar1-content"], "bar1.txt"), "bar-renamed.txt"); | ||
form.append("bar", new File(["bar2-content"], "bar2.txt", {type: "text/bary"})); | ||
form.append("baz", new Blob(["baz-content"], {type: "text/bazzy"})); | ||
form.set("qux", new Blob(["qux-content"]), "qux\n\"\\.txt"); | ||
|
||
{ | ||
let resp = new Response(form); | ||
let text = await resp.text(); | ||
let roundtrip = await new Response(text, {headers: resp.headers}).formData(); | ||
if (roundtrip.get("foo") != "foo-content") { | ||
throw new Error("expected round-trip turns into string (wrong, but backwards-compatible)"); | ||
} | ||
} | ||
|
||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Workerd = import "/workerd/workerd.capnp"; | ||
|
||
const unitTestsLegacy :Workerd.Config = ( | ||
services = [ | ||
( name = "form-data-legacy-test", | ||
worker = ( | ||
modules = [ | ||
(name = "worker", esModule = embed "form-data-legacy-test.js") | ||
], | ||
compatibilityDate = "2023-01-15", | ||
compatibilityFlags = [ | ||
"nodejs_compat", | ||
"formdata_parser_converts_files_to_strings" | ||
], | ||
) | ||
), | ||
], | ||
); | ||
|
Oops, something went wrong.