Skip to content

Commit 2826583

Browse files
authored
Merge branch 'main' into patch-mail-templates-1
2 parents 12f7884 + 5fe3296 commit 2826583

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

modules/csv/csv.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func CreateReader(input io.Reader, delimiter rune) *stdcsv.Reader {
3030
// thus would change `\t\t` to just `\t` or ` ` (two spaces) to just ` ` (single space)
3131
rd.TrimLeadingSpace = true
3232
}
33+
// Don't force validation of every row to have the same number of entries as the first row.
34+
rd.FieldsPerRecord = -1
3335
return rd
3436
}
3537

modules/csv/csv_test.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ j, ,\x20
9494
},
9595
expectedDelimiter: ',',
9696
},
97+
// case 3 - every delimiter used, default to comma and handle differing number of fields per record
98+
{
99+
csv: `col1,col2
100+
a;b
101+
c@e
102+
f g
103+
h|i
104+
jkl`,
105+
expectedRows: [][]string{
106+
{"col1", "col2"},
107+
{"a;b"},
108+
{"c@e"},
109+
{"f g"},
110+
{"h|i"},
111+
{"jkl"},
112+
},
113+
expectedDelimiter: ',',
114+
},
97115
}
98116

99117
for n, c := range cases {
@@ -119,21 +137,6 @@ func TestDetermineDelimiterShortBufferError(t *testing.T) {
119137
assert.Nil(t, rd, "CSV reader should be mnil")
120138
}
121139

122-
func TestDetermineDelimiterReadAllError(t *testing.T) {
123-
rd, err := CreateReaderAndDetermineDelimiter(nil, strings.NewReader(`col1,col2
124-
a;b
125-
c@e
126-
f g
127-
h|i
128-
jkl`))
129-
assert.NoError(t, err, "CreateReaderAndDetermineDelimiter() shouldn't throw error")
130-
assert.NotNil(t, rd, "CSV reader should not be mnil")
131-
rows, err := rd.ReadAll()
132-
assert.Error(t, err, "RaadAll() should throw error")
133-
assert.ErrorIs(t, err, csv.ErrFieldCount)
134-
assert.Empty(t, rows, "rows should be empty")
135-
}
136-
137140
func TestDetermineDelimiter(t *testing.T) {
138141
cases := []struct {
139142
csv string

0 commit comments

Comments
 (0)