Skip to content

fix(serialization): fix quote stripping bounds in TextParseNode and add tests - #2223

Merged
Vincent Biret (baywet) merged 4 commits into
microsoft:mainfrom
hardikkaurani:fix/text-parsenode-quoted-strings
Oct 27, 2026
Merged

Vincent Biret (baywet) merged 4 commits into
microsoft:mainfrom
hardikkaurani:fix/text-parsenode-quoted-strings

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request resolves a substring bounds calculation bug and index-out-of-bounds edge cases in TextParseNode, and adds test coverage for TextSerializationWriter:

  1. Quote stripping bounds:
    • In TextParseNode, when rawText starts and ends with double quotes, rawText.substring(1, rawText.length() - 2) previously evaluated with an off-by-one upper bound. In Java, substring(begin, end) is exclusive of end, meaning length() - 2 dropped the trailing character of the inner content (e.g. "\"hello world\"" became "hello worl"). The end index is corrected to rawText.length() - 1.
  2. Bounds safety:
    • Added rawText.length() >= 2 guard before attempting quote stripping. Previously:
      • An empty quoted string ("\"\"", length 2) evaluated rawText.length() - 2 == 0, throwing StringIndexOutOfBoundsException on substring(1, 0).
      • A single quote string ("\"", length 1) matched both startsWith("\"") and endsWith("\""), throwing StringIndexOutOfBoundsException on substring(1, -1).
  3. Test coverage:
    • Added test cases in TextParseNodeTest for quoted strings, empty quoted strings, single quote strings, and unquoted strings.
    • Added TextSerializationWriterTest covering string, boolean, integer, and byte array serialization, single-value restrictions, and structured data rejection.

Verification

  • Spotless formatting checks pass: ./gradlew :components:serialization:text:spotlessCheck.
  • All tests in components/serialization/text pass: 15 passing tests.

@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner October 27, 2026 08:16
Copilot AI balanced review requested due to automatic review settings October 27, 2026 08:16

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.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

This PR addresses an index calculation issue and edge cases in TextParseNode:

  1. Quote stripping bounds: In Java, String.substring(begin, end) has an exclusive upper bound. Calling substring(1, rawText.length() - 2) was stripping the last character of any quoted string (e.g. "\"hello world\"" parsed as "hello worl"). This is corrected to rawText.length() - 1.
  2. Length check and index safety: Added rawText.length() >= 2 guard. Previously, empty quotes ("\"\"") and single quotes ("\"") resulted in StringIndexOutOfBoundsException because length() - 2 evaluated to 0 or -1.
  3. Test coverage:
    • Added unit tests in TextParseNodeTest for quoted strings, empty quoted strings, single quote strings, and unquoted strings.
    • Added TextSerializationWriterTest to validate primitives, single-value enforcement, and structured data handling.

All tests pass (15 passed) and Spotless formatting is verified locally.

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

The narrow bounds correction handles the reported edge cases correctly, and the added tests cover the affected behavior with no unresolved findings.

No open issues 🎉

Review effort: Balanced

…tParseNode

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…onWriter

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
@hardikkaurani
Hardik K (hardikkaurani) force-pushed the fix/text-parsenode-quoted-strings branch from 252562b to 90ff242 Compare October 27, 2026 13:45
Copilot AI balanced review requested due to automatic review settings October 27, 2026 13: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.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

I have updated the branch to address the SpotBugs \OS_OPEN_STREAM\ failure reported in :components:serialization:text:spotbugsTest. Specifically, the stream reading helper in \TextSerializationWriterTest\ now uses try-with-resources to ensure both the underlying \InputStream\ and readers are safely closed on all execution paths.

Local verification:

  • ./gradlew :components:serialization:text:spotlessCheck\ passes.
  • ./gradlew :components:serialization:text:spotbugsTest\ passes cleanly with 0 violations.
  • ./gradlew :components:serialization:text:test\ passes all test suites.

All 4 commits are clean and signed-off. Ready for review when you have a moment.

@baywet
Vincent Biret (baywet) requested a balanced review from Copilot October 27, 2026 13:51

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

The narrow bounds correction handles the identified edge cases, and the added regression tests cover them with no unresolved issues.

No open issues 🎉

Review effort: Balanced

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