cloudflare / cloudflare/workerd

🐛 Bug Report — Runtime APIs: `formData` still turns empty files into strings

Open
#875 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

Our migration from Wrangler v2 to v3 has revealed a surprise: the `FormData` implementation in `workerd` still converts _empty_ files to strings. I expect these to still be `File` objects, as does my form validation library.

This is how a browser sees an empty file input:

```js
const form = document.querySelector("form");
const formData = new FormData(form);
console.log(formData.get("profileImage").constructor.name);
// File
```

But this is how it's arriving on the server under the latest `workerd` (Wrangler v3.2.0) with the latest compatibility date:

```js
const formData = await request.formData();
console.log(formData.get("profileImage").constructor.name);
// String
```

By comparison, Miniflare v2 (Wrangler v2.20.0) worked as expected:

```js
const formData = await request.formData();
console.log(formData.get("profileImage").constructor.name);
// File
```

The result is that the same code running in the browser vs. the worker parsing the same data arrives at a different `FormData` result.

Does anybody know why? Was this just an oversight when fixing the original issue? As a result, right now to make a file input optional I need to teach our validator to tolerate _either_ an empty string _or_ an empty `File` to work on both client and server.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.