Commit ab89378c authored by Damien Neil's avatar Damien Neil

encoding/csv: skip blank lines when FieldsPerRecord >= 0

Fixes #11050.

Change-Id: Ie5d16960a1f829af947d82a63fe414924cd02ff6
Reviewed-on: https://go-review.googlesource.com/10666Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
parent 4105265c
......@@ -228,16 +228,15 @@ func (r *Reader) parseRecord() (fields []string, err error) {
}
r.r.UnreadRune()
// If FieldsPerRecord is greater then 0 we can assume the final
// length of fields to be equal to FieldsPerRecord.
if r.FieldsPerRecord > 0 {
fields = make([]string, 0, r.FieldsPerRecord)
}
// At this point we have at least one field.
for {
haveField, delim, err := r.parseField()
if haveField {
// If FieldsPerRecord is greater then 0 we can assume the final
// length of fields to be equal to FieldsPerRecord.
if r.FieldsPerRecord > 0 && fields == nil {
fields = make([]string, 0, r.FieldsPerRecord)
}
fields = append(fields, r.field.String())
}
if delim == '\n' || err == io.EOF {
......
......@@ -86,6 +86,15 @@ field"`,
{"d", "e", "f"},
},
},
{
Name: "BlankLineFieldCount",
Input: "a,b,c\n\nd,e,f\n\n",
UseFieldsPerRecord: true,
Output: [][]string{
{"a", "b", "c"},
{"d", "e", "f"},
},
},
{
Name: "TrimSpace",
Input: " a, b, c\n",
......
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