From: Brad Fitzpatrick Date: Wed, 2 Nov 2011 15:30:50 +0000 (-0700) Subject: bufio: return nil line from ReadLine on error, as documented X-Git-Tag: weekly.2011-11-08~80 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bd43eac30318e062635792d44c185ac037ef98fa;p=gostls13.git bufio: return nil line from ReadLine on error, as documented R=golang-dev, adg CC=golang-dev https://golang.org/cl/5316069 --- 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