Skip to content

fix(echotest): trim single newline input - #3162

Open
lowgame wants to merge 1 commit into
labstack:masterfrom
lowgame:fix/trim-single-newline-63f8c33f
Open

lowgame wants to merge 1 commit into
labstack:masterfrom
lowgame:fix/trim-single-newline-63f8c33f

Conversation

@lowgame

@lowgame lowgame commented Oct 7, 2026

Copy link
Copy Markdown

Reproduction

TrimNewlineEnd([]byte("\n")) currently returns the original newline byte instead of an empty slice. The added regression test fails on the previous implementation with:

Should be empty, but was [10]

Root cause

The bounds guard requires the input length to be greater than one, although indexing the last byte is safe for every non-empty slice. This excludes the valid one-byte newline input.

Solution

Allow the trailing-newline check for any non-empty input and add a focused regression test for a sole newline byte.

Tests

  • go test ./echotest -run '^TestTrimNewlineEnd$' -count=1 — passed
  • go test ./... — passed
  • go vet ./... — passed
  • go test -race ./... — passed

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.

1 participant