summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKid <44045911+kidonng@users.noreply.github.com>2020-10-26 22:02:08 +0800
committerGitHub <noreply@github.com>2020-10-26 15:02:08 +0100
commit4c41ba5ad787909a478a6ef0d4e36adc05b52b9d (patch)
treee361e87311fb74ed99268355e61d6e8751f94d44
parentb65171e37df066cf7c509434c611163fc8a3c720 (diff)
fix(op_crates/fetch): ensure Request.method to be string (#8100)
Ensure "Request.method" to be the default value ("GET") if "init.method" is not defined, which follows browser's behavior.
-rw-r--r--cli/tests/unit/request_test.ts4
-rw-r--r--op_crates/fetch/26_fetch.js2
2 files changed, 5 insertions, 1 deletions
diff --git a/cli/tests/unit/request_test.ts b/cli/tests/unit/request_test.ts
index f1d5ef055..6fc8c0eb5 100644
--- a/cli/tests/unit/request_test.ts
+++ b/cli/tests/unit/request_test.ts
@@ -41,6 +41,10 @@ unitTest(function requestNonString(): void {
assertEquals(new Request(nonString).url, "http://foo/");
});
+unitTest(function methodNonString(): void {
+ assertEquals(new Request("http://foo/", { method: undefined }).method, "GET");
+});
+
unitTest(function requestRelativeUrl(): void {
// TODO(nayeemrmn): Base from `--location` when implemented and set.
assertThrows(() => new Request("relative-url"), TypeError, "Invalid URL.");
diff --git a/op_crates/fetch/26_fetch.js b/op_crates/fetch/26_fetch.js
index 887e329f9..c8b2c8794 100644
--- a/op_crates/fetch/26_fetch.js
+++ b/op_crates/fetch/26_fetch.js
@@ -990,7 +990,7 @@
this.url = new URL(String(input)).href;
}
- if (init && "method" in init) {
+ if (init && "method" in init && init.method) {
this.method = normalizeMethod(init.method);
}