Commit 5311d915 authored by Adam Langley's avatar Adam Langley

encoding/line: fix line returned after EOF

Fixes #1509.

R=r
CC=golang-dev
https://golang.org/cl/4167045
parent e6ee0d24
...@@ -105,6 +105,9 @@ func (l *Reader) ReadLine() (line []byte, isPrefix bool, err os.Error) { ...@@ -105,6 +105,9 @@ func (l *Reader) ReadLine() (line []byte, isPrefix bool, err os.Error) {
l.buf = l.buf[:oldLen+n] l.buf = l.buf[:oldLen+n]
if readErr != nil { if readErr != nil {
l.err = readErr l.err = readErr
if len(l.buf) == 0 {
return nil, false, readErr
}
} }
} }
panic("unreachable") panic("unreachable")
......
...@@ -7,6 +7,7 @@ package line ...@@ -7,6 +7,7 @@ package line
import ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil"
"os" "os"
"testing" "testing"
) )
...@@ -108,3 +109,25 @@ func TestReadAfterLines(t *testing.T) { ...@@ -108,3 +109,25 @@ func TestReadAfterLines(t *testing.T) {
t.Errorf("bad result for Read: got %q; expected %q", outbuf.String(), restData) t.Errorf("bad result for Read: got %q; expected %q", outbuf.String(), restData)
} }
} }
func TestReadEmptyBuffer(t *testing.T) {
l := NewReader(bytes.NewBuffer(nil), 10)
line, isPrefix, err := l.ReadLine()
if err != os.EOF {
t.Errorf("expected EOF from ReadLine, got '%s' %t %s", line, isPrefix, err)
}
}
func TestLinesAfterRead(t *testing.T) {
l := NewReader(bytes.NewBuffer([]byte("foo")), 10)
_, err := ioutil.ReadAll(l)
if err != nil {
t.Error(err)
return
}
line, isPrefix, err := l.ReadLine()
if err != os.EOF {
t.Errorf("expected EOF from ReadLine, got '%s' %t %s", line, isPrefix, err)
}
}
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