fix #27: check if parsed headers and columns match

This commit is contained in:
2024-11-04 11:13:53 +01:00
parent ef5211e45f
commit 4dc87ac22e
4 changed files with 38 additions and 17 deletions

View File

@@ -40,6 +40,20 @@ func contains(s []int, e int) bool {
return false
}
// validate the consitency of parsed data
func ValidateConsistency(data *Tabdata) error {
expectedfields := len(data.headers)
for idx, row := range data.entries {
if len(row) != expectedfields {
return fmt.Errorf("row %d does not contain expected %d elements, but %d",
idx, expectedfields, len(row))
}
}
return nil
}
// parse columns list given with -c, modifies config.UseColumns based
// on eventually given regex
func PrepareColumns(conf *cfg.Config, data *Tabdata) error {

View File

@@ -45,6 +45,10 @@ func ProcessFiles(conf *cfg.Config, args []string) error {
return err
}
if err = ValidateConsistency(&data); err != nil {
return err
}
err = PrepareColumns(conf, &data)
if err != nil {
return err