summaryrefslogtreecommitdiff
path: root/cli/tests/unit/fetch_test.ts
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2020-12-30 14:46:08 -0800
committerGitHub <noreply@github.com>2020-12-30 23:46:08 +0100
commite568ddf99687f635abe931c1eff2b8b37be3bc54 (patch)
treef3610c6c93b0f1b7a4de071fc700440101dab5a1 /cli/tests/unit/fetch_test.ts
parent22e0ee92a6618db0168b9dfce6c598b6df207a4c (diff)
fix(op_crates/fetch): correct regexp for fetch header (#8927)
Fix bug in regular expression and make the regular expression more strict. In a string passed to new RegExp(), '[\t\s]' is identical to '[ts]' and not `/[\t\s]/`. For that, the backslash needs to be escaped in the string. Futhermore, `\t` is the tab character and is included in the special regexp value `\s` so is unnecessary. That would reduce the RegExp to new RegExp(`^${value}\\s*;?`) but there's no point in matching 0 or more space characters followed by 0 or one semi-colons as that will match no matter what follows `value`. To make it more strict, require one of space, semicolon, or end-of-string after value.
Diffstat (limited to 'cli/tests/unit/fetch_test.ts')
-rw-r--r--cli/tests/unit/fetch_test.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index 86df4a1a9..0fbf01e6b 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -251,6 +251,25 @@ unitTest(
unitTest(
{ perms: { net: true } },
+ async function fetchMultipartFormBadContentType(): Promise<void> {
+ const response = await fetch(
+ "http://localhost:4545/multipart_form_bad_content_type",
+ );
+ assert(response.body !== null);
+
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await response.formData();
+ },
+ TypeError,
+ "Invalid form data",
+ );
+ await response.body.cancel();
+ },
+);
+
+unitTest(
+ { perms: { net: true } },
async function fetchURLEncodedFormDataSuccess(): Promise<void> {
const response = await fetch(
"http://localhost:4545/cli/tests/subdir/form_urlencoded.txt",