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

fix: Multipart encoding handles missing files #115

Closed
wants to merge 1 commit into from

Conversation

dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented May 10, 2024

Relates to https://github.com/Automattic/dotcom-forge/issues/6922.
Fixes #110.

Proposed Changes

Forms can submit using multipart/form-data without a type="file"
input. When that occurs, the request's file attribute is null, so we
must 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.

  1. Create a new site.
  2. Visit the WP Admin.
  3. Install and activate the WooCommerce plugin.
  4. Navigate to WooCommerce's SettingsProducts page.
  5. Modify a setting and click the Save changes button.

Fonts Successfully Upload

Follow the steps outlined in #110.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@@ -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 || {};
Copy link
Member Author

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.

@derekblank derekblank linked an issue May 13, 2024 that may be closed by this pull request
@derekblank
Copy link
Member

derekblank commented May 13, 2024

The fix proposed in this PR also appears to resolve #110: Unable to load a font file, which is also affected by the null value returned from the request in encode-as-multipart.ts (described further in #110 (comment)).

@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.
@dcalhoun dcalhoun force-pushed the fix/multipart-encoding-handles-missing-files branch from 4101275 to 47f95b8 Compare May 13, 2024 12:10
@dcalhoun dcalhoun marked this pull request as ready for review May 13, 2024 12:18
@dcalhoun dcalhoun requested review from a team May 13, 2024 12:18
Copy link
Contributor

@fluiddot fluiddot left a 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.

Copy link
Contributor

@SiobhyB SiobhyB left a 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.

@dcalhoun
Copy link
Member Author

Superseded by #122.

@dcalhoun dcalhoun closed this May 13, 2024
@dcalhoun dcalhoun deleted the fix/multipart-encoding-handles-missing-files branch May 13, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to load a font file
4 participants