Skip to content

Yield the empty entry after a trailing separator from the span Split [patch] - #473

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/441-span-split-empty-entries
Oct 20, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/441-span-split-empty-entries

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #441

What was wrong

SpanSplitEnumerator.MoveNext looped while (!_remaining.IsEmpty). Once the last separator had been consumed, the remainder was empty and enumeration stopped. So the empty field after a trailing separator was never yielded, and an empty string yielded nothing at all. That differs from string.Split, which the doc comment says this overload replaces:

input, None before now, and string.Split
"a,b," 2 3
"," 1 2
"" 0 1
"a,," 2 3

Change

Behaviour change: the span overload now returns one more, empty, entry for an empty input or one that ends in a separator. The triage asked for this to be called out in the release notes. It is spelled out in the commit message.

Tests

  • The two tests that pinned the old "current implementation" now assert string.Split's results: "" gives one empty part and ",," gives three.
  • New test: SpanSplitEnumerator_MatchesStringSplit_UnderEveryOption. It compares the enumerator with string.Split over leading, trailing, consecutive, only-separator and whitespace inputs, under all four option combinations. It loops over a corpus inside the test instead of using [DataRow] because of CA1062, following the existing note in SourceGeneratorTests.
  • With the SemanticString.cs change reverted, those 3 tests fail.
  • With the change, the full suite passes: 1780 succeeded, 0 failed on net10.0. The net9.0 leg could not launch in my environment, which has no .NET 9 runtime.

This branch stands alone on main, and it merges cleanly with #472.


Generated by Claude Code

…[patch]

SpanSplitEnumerator stopped as soon as its remainder was empty, so the
empty field after a trailing separator was never yielded and an empty
string yielded nothing. It now tracks when the last segment has been
read, and matches string.Split under every option: "a,b," gives three
parts, ",," three and "" one.

This changes the span overload's results for those inputs.

Fixes #441

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CcmGrWCwm3uDHcCpVZVcJU
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit ab5e863 into main Oct 20, 2026
16 checks passed
@matt-edmondson
matt-edmondson deleted the fix/441-span-split-empty-entries branch October 20, 2026 01:11
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.

SemanticString.Split(char) drops trailing and lone empty entries: "a,b," yields 2 parts where string.Split yields 3, and "" yields none

2 participants