Repository navigation
[patch] Skip empty split entries in a loop, and honour TrimEntries and combined options - #383
Merged
Merged
Conversation
…d combined options SpanSplitEnumerator.MoveNext skipped an empty entry by calling itself, so a long run of separators with RemoveEmptyEntries overflowed the stack and terminated the process. It now loops. The options are also tested as flags rather than with ==, so RemoveEmptyEntries | TrimEntries removes empty entries, and TrimEntries trims each entry, matching string.Split. The trailing-empty-entry behaviour is unchanged. Fixes #298 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MZE6sRR8wRTGhthCM8sL2M
|
This was referenced Oct 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #298
What changed
This rewrites
SemanticString.SpanSplitEnumerator.MoveNext(), as the issue suggested:MoveNext()again, adding one stack frame per empty entry. One million commas followed byx, split withRemoveEmptyEntries, aborted the process withStack overflow.(exit code 134). That is no longer possible._options == RemoveEmptyEntries, soRemoveEmptyEntries | TrimEntriesremoved nothing.TrimEntriesis applied. Each entry is trimmed before the empty check, so"a, ,b"with both flags gives[a, b], the same asstring.Split.StringSplitOptions.TrimEntries. The enumerator uses a private constant with the same value (2), so a .NET 5+ caller passing the named member gets the same behaviour on every target.As the issue asked, the trailing-empty-entry behaviour is unchanged:
"a,b,"still gives 2 parts, andSpanSplitEnumerator_OnlySeparators_HandlesCorrectlystill passes.Tests
New tests in
SemanticStringAdditionalTests:..._LongRunOfSeparators_DoesNotOverflowTheStack: 1,000,000 separators followed byxgives exactly["x"]...._RemoveEmptyEntriesWithTrimEntries_RemovesWhitespaceEntries:"a, ,b"gives[a, b]...._RemoveEmptyEntriesWithTrimEntries_RemovesEmptyEntries:"a,,b"gives[a, b]...._TrimEntries_TrimsEachEntry:" a , b , ,c"gives[a, b, "", c].With the fix reverted, the three options tests fail and the overflow test crashes the test host with
Stack overflow.. With the fix, all of them pass. The fullSemantics.Testsuite passes: 1450 passed, 8 skipped, 0 failed.Semantics.Stringsbuilds cleanly for all targets, including with the local Sonar analyzers.🤖 Generated with Claude Code
https://claude.ai/code/session_01MZE6sRR8wRTGhthCM8sL2M
Generated by Claude Code