diff --git a/cli/js/web/body.ts b/cli/js/web/body.ts index 6e376de37f..8f5b48ad8a 100644 --- a/cli/js/web/body.ts +++ b/cli/js/web/body.ts @@ -25,6 +25,8 @@ function validateBodyType(owner: Body, bodySource: BodyInit | null): boolean { return true; } else if (bodySource instanceof FormData) { return true; + } else if (bodySource instanceof URLSearchParams) { + return true; } else if (!bodySource) { return true; // null body is fine } @@ -193,7 +195,10 @@ export class Body implements domTypes.Body { ); } else if (this._bodySource instanceof ReadableStreamImpl) { return bufferFromStream(this._bodySource.getReader()); - } else if (this._bodySource instanceof FormData) { + } else if ( + this._bodySource instanceof FormData || + this._bodySource instanceof URLSearchParams + ) { const enc = new TextEncoder(); return Promise.resolve( enc.encode(this._bodySource.toString()).buffer as ArrayBuffer diff --git a/cli/tests/unit/body_test.ts b/cli/tests/unit/body_test.ts index a6df3102e6..df824e1ae4 100644 --- a/cli/tests/unit/body_test.ts +++ b/cli/tests/unit/body_test.ts @@ -72,3 +72,10 @@ unitTest( assertEquals(formData.get("field_2")!.toString(), ""); } ); + +unitTest({ perms: {} }, async function bodyURLSearchParams(): Promise { + const body = buildBody(new URLSearchParams({ hello: "world" })); + + const text = await body.text(); + assertEquals(text, "hello=world"); +});