Skip to content

Keep a CRLF split across two reads as one line break - #86

Merged
matt-edmondson merged 2 commits into
mainfrom
claude/crlf-split-across-reads
Sep 27, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
claude/crlf-split-across-reads

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #85

What changed

LineOutputHandler.ProcessDataByLine used to call ReplaceLineEndings() on each incoming chunk. When a read boundary fell between \r and \n, one CRLF turned into two line breaks, and the handler raised an extra empty line.

The handler now appends the raw chunk to the buffer and finds line endings in the buffered text:

  • LF, CRLF and a lone CR each end a line, along with NEL, LS, PS and FF, which is the same set ReplaceLineEndings recognizes. A lone CR still splits, as it did before.
  • A CR at the very end of the buffer stays buffered until the next chunk shows whether an LF follows it.

Tests

  • HandleStandardOutputDataShouldTreatCrlfSplitAcrossChunksAsOneLineBreak and its stderr twin feed "x\r" and then "\ny\n", and expect the lines x and y.
  • HandleStandardOutputDataShouldHoldBackTrailingCarriageReturn checks that the trailing CR stays buffered.
  • HandleStandardOutputDataShouldSplitOnEveryLineEndingKind checks that mixed CRLF, CR and LF input splits the same way it did before.

With the fix temporarily reverted, the first three tests fail. With the fix in place, the full suite passes on Linux/net10.0: 45 passed, 2 skipped (the elevation tests that are Windows-only).

🤖 Generated with Claude Code

https://claude.ai/code/session_01CGpRxGxuvhstHo5zXQoWSA


Generated by Claude Code

LineOutputHandler normalized line endings per chunk, so a chunk ending
in CR followed by one starting with LF became two line breaks and raised
a spurious empty line. Recognize line endings on the buffered text
instead, and hold a trailing CR back until the next chunk shows whether
an LF follows.

Fixes #85

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

Also use the MSTest assertions the analyzer suggests in the new tests.

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

Copy link
Copy Markdown

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.

LineOutputHandler emits a spurious empty line when a CRLF line ending is split across two reads

2 participants