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: Multipart encoding handles missing files #115
Conversation
@@ -17,7 +17,7 @@ export async function encodeAsMultipart( req: Express.Request ) { | |||
parts.push( textEncoder.encode(value) ); | |||
parts.push( `\r\n` ); | |||
} | |||
const files = req.files; | |||
const files = req.files || {}; |
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.
A similar fallback value existed in previous iteration of the logic that inspired this function. Here, we reinstate the fallback value to handle multipart/form-data
submissions that do not contain files.
Tangentially related, I responded to a suggestion that we might remove this logic altogether, but I do not think that is possible without implementing different logic in its place.
The fix proposed in this PR also appears to resolve #110: Unable to load a font file, which is also affected by the @dcalhoun I've linked #110 as a Development issue to be resolved by this PR. Happy to help with further testing when ready. |
Forms can submit using `multipart/form-data` without an `type="file"` input. When that occurs, the request's file attribute is `null`, so we must provide a fallback value to avoid errors.
4101275
to
47f95b8
Compare
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.
LGTM 🎊 ! I confirmed that both test cases WooCommerce Settings Persist Successfully
and Fonts Successfully Upload
succeed.
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.
I also verified these changes fix the two outlined issues! 🙌
I noticed some other issues with WooCommerce while testing this, which I'll log separately.
Superseded by #122. |
Relates to https://github.com/Automattic/dotcom-forge/issues/6922.
Fixes #110.
Proposed Changes
Forms can submit using
multipart/form-data
without atype="file"
input. When that occurs, the request's file attribute is
null
, so wemust provide a fallback value to avoid errors.
Testing Instructions
WooCommerce Settings Persist Successfully
Note
Database errors outlined in https://github.com/Automattic/dotcom-forge/issues/6922 remain and will be addressed separately.
Fonts Successfully Upload
Follow the steps outlined in #110.
Pre-merge Checklist