Skip to content

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

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

Vincent Biret (baywet) merged 4 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)

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 serialization changes to support MIME parameters and case-insensitive content types.

No open issues 🎉

Review effort: Balanced

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet) , whenever you get a chance, could you please review this PR and merge it if everything looks good? Thank you for your time!

Copilot AI balanced review requested due to automatic review settings November 13, 2026 12:25

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.

Install the Java 8 compiler required by -Pjava8=true instead of relying on the hosted runner image. Keep Java 21 as the default JVM for Gradle.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: de23e4a2-18d4-4f3f-a50e-d16751ed83b7
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
auto-merge was automatically disabled November 13, 2026 13:10

Head branch was pushed to by a user without write access

Copilot AI balanced review requested due to automatic review settings November 13, 2026 13:10
@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Cherry-picked the JDK 8 toolchain fix from #2249 — the ubuntu-latest runner image dropped Java 8, so the -Pjava8=true compatibility build was failing on toolchain resolution. CI should be green now.

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.

@baywet

Copy link
Copy Markdown
Member

Blocked by #2249, which explicitly installs the Java 8 toolchain required by the build workflow on Ubuntu 26.04. The corrected Java 8 build passes on that PR, and auto-merge is enabled.

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(I'm not sure my approval will count since the last commit is mine)

@baywet
Vincent Biret (baywet) added this pull request to the merge queue Nov 13, 2026
Merged via the queue into microsoft:main with commit 460d9b9 Nov 13, 2026
16 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Nov 13, 2026
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