-
Notifications
You must be signed in to change notification settings - Fork 24
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
fix: empty filename should not be treated as string #28
Conversation
🦋 Changeset detectedLatest commit: e0b02f3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/fetch/test/request.js
Outdated
@@ -338,6 +338,7 @@ describe('Request', () => { | |||
ogFormData.append('a', 1); | |||
ogFormData.append('b', 2); | |||
ogFormData.append('file', new File(['content'], 'file.txt')); | |||
ogFormData.append('empty-file', new File([], '', { type: 'application/octet-stream' })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be worth adding a comment/link here indicating this is exactly what happens to empty file inputs when constructing the form data set (e.g. native form submission, or new FormData(someForm)
)
Perhaps a good place to test on the remix side would be in https://github.com/remix-run/remix/blob/main/integration/form-test.ts, i.e. you could a test that's currently expected to fail via |
If this is considered a patch, it will be applied to existing remix app anytime the package manager updates it. But I am a bit worry as some users might be relying on this behaviour without knowing it was wrong. export async function action({ request }) {
const formData = await request.formData();
const file = formData.get('file');
// Case 1: Simply check if file is truthy
if (file) {
// ...
}
// Case 2: Check if it is an file
if (file instanceof File) {
// ...
}
} Both cases will be always true after the patch. 😅 |
Since it's a breaking change from the POV of this package, maybe the changeset should indicate As far as bumping the web-fetch dep within remix to use this, I don't know if that's big enough to warrant |
ogFormData.append('file', Buffer.from(''), { | ||
// Note: This doesn't work at the moment due to https://github.com/form-data/form-data/issues/412. | ||
// There is a v4 released which has a fix that might handle this but I | ||
// wasn't positive if it had breaking changes that would impact us so we | ||
// can handle an upgrade separately. | ||
filename: '', | ||
contentType: 'application/octet-stream', | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jacob-ebey Would love your eyes here. I think this is the equivalent using the node FormData
(using an empty buffer) - but it runs into an issue in the npm form-data
package that doesn't support empty string filenames - but that's exactly what web browsers submit:
Since it's not an issue for the bug at hand, I figured we could deal with a form-data
PR and/or update separately.
I don't think this would warrant a |
Thanks! :) |
If you create a FormData object on the browser with empty file input, a default empty file entry (i.e.
new File([], '')
) would be generated. However, this is presented as an empty string instead when you read it on the server.You can test it here.
I am not sure where to add this test. Let me know if you have any suggestion.