aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/csv/reader.go
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2017-12-01 11:41:46 -0800
committerJoe Tsai <thebrokentoaster@gmail.com>2017-12-05 18:44:31 +0000
commit0b3b5113c0bbc62306a0404b235cbdf5a431bf67 (patch)
tree30be829df15b36ba219cd618cd01d39d639ebe3b /src/encoding/csv/reader.go
parent8f2a9267c814538485dd3459910bc8e6de2ef2bb (diff)
downloadgo-0b3b5113c0bbc62306a0404b235cbdf5a431bf67.tar.xz
encoding/csv: truncate carriage returns at EOF
This fixes a regression where only CRLF was folded into LF at EOF. Now, we also truncate trailing CR at EOF to preserve the old behavior. Every one of the test cases added exactly matches the behavior of Go1.9, even if the results are somewhat unexpected. Fixes #22937 Change-Id: I1bc6550533163ae489ea77ec1e598163267b7eec Reviewed-on: https://go-review.googlesource.com/81577 Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/encoding/csv/reader.go')
-rw-r--r--src/encoding/csv/reader.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/encoding/csv/reader.go b/src/encoding/csv/reader.go
index 1350f3ebdd..2efc7ad094 100644
--- a/src/encoding/csv/reader.go
+++ b/src/encoding/csv/reader.go
@@ -224,6 +224,10 @@ func (r *Reader) readLine() ([]byte, error) {
}
if len(line) > 0 && err == io.EOF {
err = nil
+ // For backwards compatibility, drop trailing \r before EOF.
+ if line[len(line)-1] == '\r' {
+ line = line[:len(line)-1]
+ }
}
r.numLine++
// Normalize \r\n to \n on all input lines.