0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-09 13:49:37 -04:00

fix(ext/fetch): support empty formdata (#16165)

This PR adds support for empty `FormData` parsing in
`Response`/`Request`

```js
new Response(new FormData()).formData()
```

ref: https://github.com/web-platform-tests/wpt/issues/28607
This commit is contained in:
Marcos Casagrande 2022-10-07 13:59:30 +02:00 committed by GitHub
parent e136bd86b3
commit a5d55fe6ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 18 deletions

View file

@ -393,9 +393,19 @@
* @returns {FormData} * @returns {FormData}
*/ */
parse() { parse() {
// Body must be at least 2 boundaries + \r\n + -- on the last boundary. // To have fields body must be at least 2 boundaries + \r\n + --
// on the last boundary.
if (this.body.length < (this.boundary.length * 2) + 4) { if (this.body.length < (this.boundary.length * 2) + 4) {
throw new TypeError("Form data too short to be valid."); const decodedBody = core.decode(this.body);
const lastBoundary = this.boundary + "--";
// check if it's an empty valid form data
if (
decodedBody === lastBoundary ||
decodedBody === lastBoundary + "\r\n"
) {
return new FormData();
}
throw new TypeError("Unable to parse body as form data.");
} }
const formData = new FormData(); const formData = new FormData();

View file

@ -3077,14 +3077,8 @@
"response-static-json.any.worker.html": true "response-static-json.any.worker.html": true
}, },
"body": { "body": {
"formdata.any.html": [ "formdata.any.html": true,
"Consume empty response.formData() as FormData", "formdata.any.worker.html": true,
"Consume empty request.formData() as FormData"
],
"formdata.any.worker.html": [
"Consume empty response.formData() as FormData",
"Consume empty request.formData() as FormData"
],
"mime-type.any.html": true, "mime-type.any.html": true,
"mime-type.any.worker.html": true "mime-type.any.worker.html": true
}, },
@ -3231,14 +3225,8 @@
"response.text() rejects if already aborted", "response.text() rejects if already aborted",
"Call text() twice on aborted response" "Call text() twice on aborted response"
], ],
"request.any.html": [ "request.any.html": true,
"Calling formData() on an aborted request", "request.any.worker.html": true,
"Aborting a request after calling formData()"
],
"request.any.worker.html": [
"Calling formData() on an aborted request",
"Aborting a request after calling formData()"
],
"cache.https.any.html": false, "cache.https.any.html": false,
"cache.https.any.worker.html": false "cache.https.any.worker.html": false
} }