diff --git a/src/pkg/bufio/bufio.go b/src/pkg/bufio/bufio.go index f4ed91b24b..0b354fda82 100644 --- a/src/pkg/bufio/bufio.go +++ b/src/pkg/bufio/bufio.go @@ -312,6 +312,9 @@ func (b *Reader) ReadLine() (line []byte, isPrefix bool, err error) { } if len(line) == 0 { + if err != nil { + line = nil + } return } err = nil diff --git a/src/pkg/bufio/bufio_test.go b/src/pkg/bufio/bufio_test.go index 0285deeb3d..1d3acea367 100644 --- a/src/pkg/bufio/bufio_test.go +++ b/src/pkg/bufio/bufio_test.go @@ -698,6 +698,17 @@ func TestLinesAfterRead(t *testing.T) { } } +func TestReadLineNonNilLineOrError(t *testing.T) { + r := NewReader(strings.NewReader("line 1\n")) + for i := 0; i < 2; i++ { + l, _, err := r.ReadLine() + if l != nil && err != nil { + t.Fatalf("on line %d/2; ReadLine=%#v, %v; want non-nil line or Error, but not both", + i+1, l, err) + } + } +} + type readLineResult struct { line []byte isPrefix bool