Skip to content

fix(serialization): support content-type parameters and case-insensitivity in form factories - #2239

Open
Hardik K (hardikkaurani) wants to merge 2 commits into
microsoft:mainfrom
hardikkaurani:fix/form-factory-content-type-parameters-and-case
Open

Hardik K (hardikkaurani) wants to merge 2 commits into
microsoft:mainfrom
hardikkaurani:fix/form-factory-content-type-parameters-and-case

Conversation

@hardikkaurani

@hardikkaurani Hardik K (hardikkaurani) commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

FormParseNodeFactory.getParseNode() and FormSerializationWriterFactory.getSerializationWriter() used strict string equality (!contentType.equals(validContentType)) to validate the content type against application/x-www-form-urlencoded.

As a result, both factories rejected valid content types that contain MIME parameters (such as application/x-www-form-urlencoded; charset=utf-8 or application/x-www-form-urlencoded; charset=UTF-8) or use case variants (e.g. APPLICATION/X-WWW-FORM-URLENCODED or Application/x-www-form-urlencoded; charset=utf-8) with an IllegalArgumentException.

Per RFC 2045 §5.1, media types and subtypes are case-insensitive and parameter-agnostic for type identification. This change brings form serialization factories to parity with TextParseNodeFactory/TextSerializationWriterFactory (#2236) and MultipartSerializationWriterFactory (#2229).

Changes

  • Commit 1 (fix): Updated FormParseNodeFactory.getParseNode() and FormSerializationWriterFactory.getSerializationWriter() to strip MIME parameters (split(";", 2)[0].trim()) and compare against the valid content type case-insensitively (equalsIgnoreCase).
  • Commit 2 (test): Added parameterized regression tests to ParseNodeFactoryTests and SerializationWriterFactoryTests asserting acceptance of content types with MIME parameters and case variations, while continuing to reject delimiter-only or invalid media types.

Verification

  • :components:serialization:form:spotlessCheck / spotlessApply: PASS
  • :components:serialization:form:spotbugsMain / spotbugsTest: PASS
  • :components:serialization:form:check: PASS (100% tests passing)
  • :components:bundle:check: PASS

…ivity in form factories

FormParseNodeFactory and FormSerializationWriterFactory previously checked content types with strict string equality against application/x-www-form-urlencoded. As a result, content types with MIME parameters (such as charset=utf-8) or case variations (such as APPLICATION/X-WWW-FORM-URLENCODED) were rejected with IllegalArgumentException.

Strip MIME parameters and compare against the valid content type case-insensitively, aligning with RFC 2045 §5.1 and matching TextParseNodeFactory and MultipartSerializationWriterFactory.

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…E parameters and case variants

Add parameterized tests in ParseNodeFactoryTests and SerializationWriterFactoryTests asserting that FormParseNodeFactory and FormSerializationWriterFactory properly accept content types with MIME parameters (such as charset=utf-8), uppercase, and mixed-case variants, while continuing to reject delimiter-only and invalid media types.

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner November 7, 2026 05:57
Copilot AI balanced review requested due to automatic review settings November 7, 2026 05:57

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), following up on the changes introduced in #2236 and #2229, FormParseNodeFactory and FormSerializationWriterFactory were still using strict string equality against application/x-www-form-urlencoded.

This PR brings the form serialization factories to parity by stripping MIME parameters (such as charset=utf-8) and handling media types case-insensitively per RFC 2045 §5.1. Parameterized regression tests covering charset parameters, case variations, and delimiter edge cases have been added, and all local spotless, spotbugs, and Gradle test suites pass cleanly.

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 block the form content-type normalization change.

No open issues 🎉

Review effort: Balanced

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Thanks Vincent Biret (@baywet)

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Nov 9, 2026

This branch has not been deployed

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

Labels

None yet

Projects

Status: In Progress 🚧

Development

Successfully merging this pull request may close these issues.

3 participants