Skip to content

fix: prevent IndexOutOfRangeException in StringExtensions.ToSnakeCase - #8389

Open
Austin Aviv (austinaviv) wants to merge 7 commits into
microsoft:mainfrom
austinaviv:fix-tosnakecase-out-of-range
Open

Austin Aviv (austinaviv) wants to merge 7 commits into
microsoft:mainfrom
austinaviv:fix-tosnakecase-out-of-range

Conversation

@austinaviv

Copy link
Copy Markdown

Summary

Fixes IndexOutOfRangeException in StringExtensions.ToSnakeCase under multiple edge cases:

  • Guard against accessing
    ameSpan[i + 1] when the input string ends with a hyphen.
  • Return empty string early if stripping generic arguments with < results in an empty span before indexing
    ameSpan[0].
  • Handle leading hyphen followed by uppercase without buffer overrun.
  • Return sliced span
    ew string(span[..counter]) to avoid returning uninitialized or null characters if fewer characters are written than allocated.
  • Add unit test coverage for trailing hyphens, generic arguments, leading hyphens with uppercase and lowercase, and consecutive hyphens.

Validation

dotnet test tests/Kiota.Builder.Tests/Kiota.Builder.Tests.csproj --no-restore --nologo --filter 'FullyQualifiedName!~KiotaSearcherTests' --verbosity quiet (2,899 passed, 2 skipped)
dotnet test tests/Kiota.Tests/Kiota.Tests.csproj (18 passed)

Fixes #8388

@austinaviv
Austin Aviv (austinaviv) requested a review from a team as a code owner October 12, 2026 02:50
Copilot AI balanced review requested due to automatic review settings October 12, 2026 02:50
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for opening this pull request! Please add a changelog entry under ## [Unreleased] in CHANGELOG.md, before the first released version section, so users can see what changed. Add bug fixes under ### Changed and new features under ### Added.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Custom '-' separators are incorrectly omitted before uppercase characters.

1 open finding
What changed in this PR

Fixes edge-case failures and malformed output in ToSnakeCase.

Changes:

  • Handles empty generic prefixes and boundary hyphens safely.
  • Returns only initialized output characters.
  • Adds regression tests for reported edge cases.
File Description
src/​Kiota.Builder/​Extensions/​StringExtensions.cs Hardens snake-case conversion logic.
tests/​Kiota.Builder.Tests/​Extensions/​StringExtensionsTests.cs Adds edge-case coverage.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Kiota.Builder/Extensions/StringExtensions.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 02:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation addresses the reported bounds errors and includes focused regression tests.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 12, 2026 02:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The span-slicing fix lacks a regression test that exercises an overallocated buffer.

0 open findings

Previously missed (1)

In code that hasn't changed since last review

Low severity Add custom-separator test for span allocation fix

tests/​Kiota.Builder.Tests/​Extensions/​StringExtensionsTests.cs:87

The new cases do not exercise the span[..counter] fix: with the default separator, each of these inputs fills the allocated span exactly, so reverting that fix would still pass. Add a custom-separator case such as "a.B".ToSnakeCase('.'), where separator counting allocates four chars but only three are written, to prevent trailing-null regressions.

🧠 Review effort: Balanced

@austinaviv

Copy link
Copy Markdown
Author

Hi maintainers, could you please approve the workflow run for this PR? Thank you!

Copilot AI balanced review requested due to automatic review settings October 13, 2026 01:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation addresses each reported failure mode with focused regression coverage.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 15, 2026 10:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The targeted fixes include regression coverage, and no unresolved blocking issues were identified.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 21, 2026 05:11
@github-actions

Copy link
Copy Markdown
Contributor

Conflicts have been resolved. A maintainer will take a look shortly.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The localized fixes address the reported failures with regression coverage and no identified blocking issues.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 21, 2026 17:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The targeted fixes address the reported failures with regression coverage and no unresolved findings.

No open issues 🎉

Review effort: Balanced

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

None yet

Development

Successfully merging this pull request may close these issues.

IndexOutOfRangeException in StringExtensions.ToSnakeCase on trailing hyphen and generic inputs

2 participants