Skip to content

fix: stop text line scanner at empty EOF - #5798

Open
lowgame wants to merge 1 commit into
zeromicro:masterfrom
lowgame:fix-text-line-scanner-eof-e24c7ae6
Open

lowgame wants to merge 1 commit into
zeromicro:masterfrom
lowgame:fix-text-line-scanner-eof-e24c7ae6

Conversation

@lowgame

@lowgame lowgame commented Sep 27, 2026

Copy link
Copy Markdown

What changed

TextLineScanner.Scan now stops when ReadString reaches EOF without returning any bytes. The regression tests cover empty input, newline-terminated input, and legitimate blank lines.

Reproduction

Before this change, scanning either an empty reader or "one\n" yielded a synthetic final empty line:

  • "" produced []string{""} instead of no lines.
  • "one\n" produced []string{"one", ""} instead of []string{"one"}.

The new regression test failed on both cases before the production change.

Root cause

bufio.Reader.ReadString returns ("", io.EOF) when no data remains, but Scan returned true for every EOF result. That made an empty EOF look like a real line.

Fix

Return true at EOF only when ReadString also returned bytes. This preserves a final unterminated line and empty lines represented by newline delimiters.

Verification

  • go test ./core/iox -run 'TestScanner|TestBadScanner' -count=1 — pass
  • go test ./core/iox -count=1 — pass
  • go test -race ./core/iox -count=1 — pass
  • go vet ./core/iox — pass
  • gofmt -l core/iox/textlinescanner.go core/iox/textlinescanner_test.go — no output
  • git diff --check — pass

A full go test ./... was attempted but did not complete on this host: an unrelated core/logx access-permission assertion fails when run as root, and later packages exhausted the available disk while compiling Kubernetes dependencies.

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