fix(csvimport): report accurate physical line numbers via FieldPos; add blank-line + zero-row tests
This commit is contained in:
@@ -17,11 +17,9 @@ type Row struct {
|
||||
func Parse(r io.Reader) ([]Row, error) {
|
||||
cr := csv.NewReader(r)
|
||||
cr.FieldsPerRecord = -1 // проверяем сами
|
||||
cr.TrimLeadingSpace = true
|
||||
|
||||
var rows []Row
|
||||
seen := map[string]bool{}
|
||||
line := 0
|
||||
for {
|
||||
rec, err := cr.Read()
|
||||
if err == io.EOF {
|
||||
@@ -30,9 +28,9 @@ func Parse(r io.Reader) ([]Row, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
line++
|
||||
line, _ := cr.FieldPos(0)
|
||||
if len(rec) == 1 && strings.TrimSpace(rec[0]) == "" {
|
||||
continue // пустая строка
|
||||
continue // encoding/csv уже пропускает голые пустые строки; это ветка ловит строки из одних пробелов
|
||||
}
|
||||
if len(rec) != 4 {
|
||||
return nil, fmt.Errorf("line %d: expected 4 columns, got %d", line, len(rec))
|
||||
|
||||
Reference in New Issue
Block a user