aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/csv/reader_test.go
diff options
context:
space:
mode:
authorJustin Nuß <nuss.justin@gmail.com>2017-08-02 19:18:30 +0200
committerIan Lance Taylor <iant@golang.org>2017-08-14 04:45:38 +0000
commit5d14ac74f614631a38be95cc9724ff38068c6c76 (patch)
treedec1fcac0d9ff56992966bdf4c0f68f154579843 /src/encoding/csv/reader_test.go
parent342d25fc05a915f267e9d4f0bdc13fb04e014a2b (diff)
downloadgo-5d14ac74f614631a38be95cc9724ff38068c6c76.tar.xz
encoding/csv: report line start line in errors
Errors returned by Reader contain the line where the Reader originally encountered the error. This can be suboptimal since that line does not always correspond with the line the current record/field started at. This can easily happen with LazyQuotes as seen in #19019, but also happens for example when a quoted fields has no closing quote and the parser hits EOF before it finds another quote. When this happens finding the erroneous field can be somewhat complicated and time consuming, and in most cases it would be better to report the line where the record started. This change updates Reader to keep track of the line on which a record begins and uses it for errors instead of the current line, making it easier to find errors. Although a user-visible change, this should have no impact on existing code, since most users don't explicitly work with the line in the error and probably already expect the new behaviour. Updates #19019 Change-Id: Ic9bc70fad2651c69435d614d537e7a9266819b05 Reviewed-on: https://go-review.googlesource.com/52830 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/encoding/csv/reader_test.go')
-rw-r--r--src/encoding/csv/reader_test.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/encoding/csv/reader_test.go b/src/encoding/csv/reader_test.go
index 5ab1b61256..76e94bab3e 100644
--- a/src/encoding/csv/reader_test.go
+++ b/src/encoding/csv/reader_test.go
@@ -270,6 +270,20 @@ x,,,
{"c", "d"},
},
},
+ { // issue 19019
+ Name: "RecordLine1",
+ Input: "a,\"b\nc\"d,e",
+ Error: `extraneous " in field`,
+ Line: 1,
+ Column: 1,
+ },
+ {
+ Name: "RecordLine2",
+ Input: "a,b\n\"d\n\n,e",
+ Error: `extraneous " in field`,
+ Line: 2,
+ Column: 2,
+ },
}
func TestRead(t *testing.T) {