Skip to content

fix(multipart): support content-type parameters and case-insensitivity in MultipartSerializationWriterFactory - #2229

Merged
Vincent Biret (baywet) merged 2 commits into
microsoft:mainfrom
hardikkaurani:fix/multipart-factory-content-type-parameters-and-case
Nov 2, 2026
Merged

Vincent Biret (baywet) merged 2 commits into
microsoft:mainfrom
hardikkaurani:fix/multipart-factory-content-type-parameters-and-case

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Summary

MultipartSerializationWriterFactory.getSerializationWriter() uses strict string equality (contentType.equals(validContentType)) to validate the content type. This causes the factory to reject valid content types that include MIME parameters (e.g., multipart/form-data; boundary=abc) or use different casing (e.g., MULTIPART/FORM-DATA).

Per RFC 2045 §5.1, content type matching should be case-insensitive and must ignore parameters.

Changes

  • Commit 1 (fix): Updated the content-type comparison in MultipartSerializationWriterFactory.getSerializationWriter() to strip MIME parameters (split on ;, trim) and compare case-insensitively (equalsIgnoreCase).
  • Commit 2 (tests): Added parameterized regression tests covering content types with parameters (; boundary=abc, ; charset=utf-8), uppercase (MULTIPART/FORM-DATA), mixed case (Multipart/Form-Data), and uppercase with parameters.

Context

While SerializationWriterFactoryRegistry strips parameters before delegating to the factory, the factory can also be used directly (not through the registry), in which case parameterized or case-variant content types would incorrectly throw IllegalArgumentException.

This is the same bug pattern already fixed in the TypeScript, Go multipart, Go form, and Go text serialization libraries.

Verification

  • All existing tests pass
  • New parameterized tests pass
  • SpotlessCheck passes
  • SpotBugs (main + test) passes
  • Full :components:serialization:multipart:check passes

Copilot AI balanced review requested due to automatic review settings November 1, 2026 21:45
@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner November 1, 2026 21:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Delimiter-only content types now trigger ArrayIndexOutOfBoundsException instead of the expected IllegalArgumentException because split discards all empty segments.

1 open issue

Review effort: Balanced

@hardikkaurani
Hardik K (hardikkaurani) force-pushed the fix/multipart-factory-content-type-parameters-and-case branch from 04b5d8d to 9e4d21e Compare November 2, 2026 12:44
Copilot AI balanced review requested due to automatic review settings November 2, 2026 12:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

I've pushed an update addressing the review feedback:

  • Passed a positive limit to split(";", 2) in MultipartSerializationWriterFactory so that delimiter-only inputs (like ";" or ";;") preserve empty segments and properly trigger IllegalArgumentException instead of an ArrayIndexOutOfBoundsException.
  • Added parameterized regression tests covering delimiter-only and missing media-type variants (";", ";;", "; boundary=abc").
  • Verified full build passes locally (:components:serialization:multipart:check, Spotless, SpotBugs, and all test suites).

Ready for your review when you have a moment. Thanks!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the multipart content-type normalization change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

3 participants