Skip to content

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

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

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

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Summary

Fixes #2235

TextParseNodeFactory.getParseNode() and TextSerializationWriterFactory.getSerializationWriter() used strict string equality (!contentType.equals(validContentType)) to validate the content type against text/plain.

This caused both factories to reject valid content types that contain MIME parameters (such as text/plain; charset=utf-8 or text/plain; charset=UTF-8) or use case variants (e.g. TEXT/PLAIN or Text/Plain; charset=utf-8).

Per RFC 2045 §5.1, media types and subtypes are case-insensitive and parameter-agnostic for type identification.

Changes

  • Commit 1 (fix): Updated TextParseNodeFactory and TextSerializationWriterFactory to strip MIME parameters (split(";", 2)[0].trim()) and compare against the valid content type case-insensitively (equalsIgnoreCase), matching the pattern implemented in MultipartSerializationWriterFactory (fix(multipart): support content-type parameters and case-insensitivity in MultipartSerializationWriterFactory #2229).
  • Commit 2 (tests): Added TextParseNodeFactoryTest with unit and parameterized regression tests covering valid text/plain, content types with charset parameters, uppercase, mixed case, invalid types, empty strings, and delimiter-only inputs.
  • Commit 3 (tests): Added TextSerializationWriterFactoryTest with corresponding unit and parameterized regression tests for the writer factory.

Verification

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

…ivity in text factories

Strip MIME parameters and compare content types case-insensitively in TextParseNodeFactory and TextSerializationWriterFactory per RFC 2045.

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
… and case-insensitivity in TextParseNodeFactory

Add unit and parameterized tests verifying TextParseNodeFactory accepts MIME parameters and case variants per RFC 2045.

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
… and case-insensitivity in TextSerializationWriterFactory

Add unit and parameterized tests verifying TextSerializationWriterFactory accepts MIME parameters and case variants per RFC 2045.

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

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

Vincent Biret (@baywet) Opened this PR to address #2235 by aligning TextParseNodeFactory and TextSerializationWriterFactory with RFC 2045 §5.1, mirroring the fix recently merged for MultipartSerializationWriterFactory (#2229).

Previously, both text factories used strict string equality (!contentType.equals("text/plain")), causing them to reject valid text payloads specifying standard MIME parameters (e.g., text/plain; charset=utf-8) or case variants (TEXT/PLAIN).

The PR is structured across 3 focused commits:

  1. fix(serialization): Strips MIME parameters and compares against text/plain case-insensitively across both factories.
  2. test(serialization): Adds TextParseNodeFactoryTest with unit and parameterized coverage for parameters, casing, invalid types, empty strings, and delimiters.
  3. test(serialization): Adds TextSerializationWriterFactoryTest with corresponding unit and parameterized test coverage.

Verified locally: spotlessCheck, spotbugsMain, spotbugsTest, and :components:serialization:text:check 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 remain for the changes supporting parameterized and case-varied text/plain media types.

No open issues 🎉

Review effort: Balanced

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Nov 4, 2026
@baywet
Vincent Biret (baywet) merged commit 395e40f into microsoft:main Nov 4, 2026
9 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Nov 4, 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.

TextParseNodeFactory and TextSerializationWriterFactory reject content types with MIME parameters or case variants

3 participants