Skip to content

Fix IndexOutOfRangeException in GetIndex - #5

Merged
SoftStoneDevelop merged 1 commit into
SoftStoneDevelop:mainfrom
armadavalor:fix/getindex-index-out-of-range
Oct 26, 2026
Merged

SoftStoneDevelop merged 1 commit into
SoftStoneDevelop:mainfrom
armadavalor:fix/getindex-index-out-of-range

Conversation

@armadavalor

Copy link
Copy Markdown
Contributor

GetIndex threw IndexOutOfRangeException when the search string matched only the tail of a stored item (for example items "12", "34" and a search for "4"), or when the search string was empty. In IsTheSameSequence, searchStr was already fully consumed but the loop kept reading searchStr[-1]. The fix returns "no match" once the search string is exhausted before the item boundary is reached, which matches the documented behaviour (only whole stored parts are compared).

Added GetIndexSearchShorterThanItem to GetIndexFixture; it fails with the exception before the change and passes after.

Tested: dotnet test -f net10.0 -> Passed: 61, Failed: 0. Other target frameworks (net462, net9.0) not run; the changed code is only compiled for NET6_0_OR_GREATER.

Closes #4

@SoftStoneDevelop
SoftStoneDevelop merged commit 35a2495 into SoftStoneDevelop:main Oct 26, 2026
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

2 participants