Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing test for empty file input uploads #6816

Merged
merged 3 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/large-dodos-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/node": patch
---

- Upgrade to [`@remix-run/web-fetch@4.3.5`](https://github.com/remix-run/web-std-io/releases/tag/%40remix-run%2Fweb-fetch%404.3.5). Submitted empty file inputs are now correctly parsed out as empty `File` instances instead of being surfaced as an empty string via `request.formData()`
46 changes: 46 additions & 0 deletions integration/form-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,39 @@ test.describe("Forms", () => {
}
`,

"app/routes/empty-file-upload.jsx": js`
import { json } from "@remix-run/server-runtime";
import { Form, useActionData } from "@remix-run/react";

export async function action({ request }) {
let formData = await request.formData();
return json({
text: formData.get('text'),
file: {
name: formData.get('file').name,
size: formData.get('file').size,
},
fileMultiple: formData.getAll('fileMultiple').map(f => ({
name: f.name,
size: f.size,
})),
})
}

export default function() {
const actionData = useActionData();
return (
<Form method="post" encType="multipart/form-data">
<input name="text" />
<input type="file" name="file" />
<input type="file" name="fileMultiple" multiple />
<button type="submit">Submit</button>
{actionData ? <p id="action-data">{JSON.stringify(actionData)}</p> : null}
</Form>
)
}
`,

// Generic route for outputting url-encoded form data (either from the request body or search params)
//
// TODO: refactor other tests to use this
Expand Down Expand Up @@ -1065,6 +1098,19 @@ test.describe("Forms", () => {
);
});

test("empty file inputs resolve to File objects on the server", async ({
page,
}) => {
let app = new PlaywrightFixture(appFixture, page);

await app.goto("/empty-file-upload");
await app.clickSubmitButton("/empty-file-upload");
await page.waitForSelector("#action-data");
expect((await app.getElement("#action-data")).text()).toContain(
'{"text":"","file":{"name":"","size":0},"fileMultiple":[{"name":"","size":0}]}'
);
});

test("pathless layout routes are ignored in form actions", async ({
page,
}) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"dependencies": {
"@remix-run/server-runtime": "1.18.1",
"@remix-run/web-fetch": "^4.3.4",
"@remix-run/web-fetch": "^4.3.5",
"@remix-run/web-file": "^3.0.2",
"@remix-run/web-stream": "^1.0.3",
"@web3-storage/multipart-parser": "^1.0.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2602,10 +2602,10 @@
"@remix-run/web-stream" "^1.0.0"
web-encoding "1.1.5"

"@remix-run/web-fetch@^4.3.4":
version "4.3.4"
resolved "https://registry.npmjs.org/@remix-run/web-fetch/-/web-fetch-4.3.4.tgz#6149582fa2199b8e2a35d4e653ba05772bd0e675"
integrity sha512-AUM1XBa4hcgeNt2CD86OlB5aDLlqdMl0uJ+89R8dPGx07I5BwMXnbopCaPAkvSBIoHeT/IoLWIuZrLi7RvXS+Q==
"@remix-run/web-fetch@^4.3.5":
version "4.3.5"
resolved "https://registry.npmjs.org/@remix-run/web-fetch/-/web-fetch-4.3.5.tgz#10e23082477e56ff496e4f02899a0389cdd249c9"
integrity sha512-cLLeNLvLRyFRhJLulzS98bb07kJ+ENkGaqUkBisdG4FNEoZF6tXtrTGLWJNJa1nAP/wFkMKEDxIP77LgAPyeow==
dependencies:
"@remix-run/web-blob" "^3.0.4"
"@remix-run/web-form-data" "^3.0.3"
Expand Down