Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ func (r *Rows) FromCSVString(s string) *Rows {
}
panic(fmt.Sprintf("Parsing CSV string failed: %s", err.Error()))
}
if len(res) != len(r.cols) {
panic(fmt.Sprintf("Expected number of values to match number of columns: expected %d, actual %d", len(r.cols), len(res)))
}

row := make([]driver.Value, len(r.cols))
for i, v := range res {
Expand Down
11 changes: 11 additions & 0 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,17 @@ func TestCSVParserInvalidInput(t *testing.T) {
t.Error("expected panic from parsing invalid CSV")
}

func TestCSVParserRejectsShortRecord(t *testing.T) {
const expectedPanic = "Expected number of values to match number of columns: expected 3, actual 2"
defer func() {
if r := recover(); r != expectedPanic {
t.Fatalf("expected panic %q, got %v", expectedPanic, r)
}
}()

NewRows([]string{"order_id", "status", "created_at"}).FromCSVString("INV-2026-0908,paid")
}

func TestWrongNumberOfValues(t *testing.T) {
// Open new mock database
db, mock, err := New()
Expand Down