File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 44 "bytes"
55 "database/sql/driver"
66 "encoding/csv"
7+ "errors"
78 "fmt"
89 "io"
910 "strings"
@@ -208,8 +209,11 @@ func (r *Rows) FromCSVString(s string) *Rows {
208209
209210 for {
210211 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 ()))
213217 }
214218
215219 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) {
461461 }
462462}
463463
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+
464473func TestWrongNumberOfValues (t * testing.T ) {
465474 // Open new mock database
466475 db , mock , err := New ()
You can’t perform that action at this time.
0 commit comments