// By default, each call to Read returns newly allocated memory owned by the caller.
ReuseRecord bool
- line int
- column int
- r *bufio.Reader
+ line int
+ recordLine int // line where the current record started
+ column int
+ r *bufio.Reader
// lineBuffer holds the unescaped fields read by readField, one after another.
// The fields can be accessed by using the indexes in fieldIndexes.
// Example: for the row `a,"b","c""d",e` lineBuffer will contain `abc"de` and
// error creates a new ParseError based on err.
func (r *Reader) error(err error) error {
return &ParseError{
- Line: r.line,
+ Line: r.recordLine,
Column: r.column,
Err: err,
}
// Each record starts on a new line. We increment our line
// number (lines start at 1, not 0) and set column to -1
// so as we increment in readRune it points to the character we read.
+ // We track the line where the record starts in recordLine for use in errors.
r.line++
+ r.recordLine = r.line
r.column = -1
// Peek at the first rune. If it is an error we are done.
{"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) {