Commit bd43eac3 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

bufio: return nil line from ReadLine on error, as documented

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5316069
parent 29a5ae65
......@@ -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
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment