File tree 2 files changed +15
-2
lines changed
2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 4
4
"bytes"
5
5
"database/sql/driver"
6
6
"encoding/csv"
7
+ "errors"
7
8
"fmt"
8
9
"io"
9
10
"strings"
@@ -208,8 +209,11 @@ func (r *Rows) FromCSVString(s string) *Rows {
208
209
209
210
for {
210
211
res , err := csvReader .Read ()
211
- if err != nil || res == nil {
212
- break
212
+ if err != nil {
213
+ if errors .Is (err , io .EOF ) {
214
+ break
215
+ }
216
+ panic (fmt .Sprintf ("Parsing CSV string failed: %s" , err .Error ()))
213
217
}
214
218
215
219
row := make ([]driver.Value , len (r .cols ))
Original file line number Diff line number Diff line change @@ -461,6 +461,15 @@ func TestCSVRowParser(t *testing.T) {
461
461
}
462
462
}
463
463
464
+ func TestCSVParserInvalidInput (t * testing.T ) {
465
+ defer func () {
466
+ recover ()
467
+ }()
468
+ _ = NewRows ([]string {"col1" , "col2" }).FromCSVString ("a,\" NULL\" \" " )
469
+ // shouldn't reach here
470
+ t .Error ("expected panic from parsing invalid CSV" )
471
+ }
472
+
464
473
func TestWrongNumberOfValues (t * testing.T ) {
465
474
// Open new mock database
466
475
db , mock , err := New ()
You can’t perform that action at this time.
0 commit comments