diff options
| author | Rob Pike <r@golang.org> | 2014-09-25 12:45:21 -0700 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2014-09-25 12:45:21 -0700 |
| commit | 74c0de8fb6ef26deece0541a7bf9337ce30c1878 (patch) | |
| tree | 9099d444b97b0831a929c05b6c0bac777fb2603b /src/bufio/scan.go | |
| parent | cfae41ff36d833719b073d1eec5f0fd535ca9e61 (diff) | |
| download | go-74c0de8fb6ef26deece0541a7bf9337ce30c1878.tar.xz | |
bufio: fix handling of empty tokens at end of line/file
Fixes #8672.
LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/145390043
Diffstat (limited to 'src/bufio/scan.go')
| -rw-r--r-- | src/bufio/scan.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/bufio/scan.go b/src/bufio/scan.go index c5714f331e..a41451524d 100644 --- a/src/bufio/scan.go +++ b/src/bufio/scan.go @@ -112,7 +112,9 @@ func (s *Scanner) Scan() bool { // Loop until we have a token. for { // See if we can get a token with what we already have. - if s.end > s.start { + // If we've run out of data but have an error, give the split function + // a chance to recover any remaining, possibly empty token. + if s.end > s.start || s.err != nil { advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil) if err != nil { s.setErr(err) |
