diff --git a/lib/GADS/Import.pm b/lib/GADS/Import.pm index 62d45364c..efaa9343c 100644 --- a/lib/GADS/Import.pm +++ b/lib/GADS/Import.pm @@ -267,8 +267,10 @@ sub _build_fields my @fields; my $column_id = $self->layout->column_id; + my $col_count = 0; foreach my $field (@$fields_in) { + $col_count++; if ( ( ($self->update_unique && $self->update_unique == $column_id->id) || @@ -298,6 +300,8 @@ sub _build_fields $search->{name} = $field if !$self->short_names; $search->{name_short} = $field if $self->short_names; my $f_rs = $self->schema->resultset('Layout')->search($search); + error __x"Empty field name in import headings (Column {column})", column => $col_count + if $field =~ /^\s*$/; error __x"Layout has more than one field named {name}", name => $field if $f_rs->count > 1; error __x"Field '{name}' in import headings not found in table", name => $field diff --git a/t/014_import.t b/t/014_import.t index 3825f1ff3..7d65cc844 100644 --- a/t/014_import.t +++ b/t/014_import.t @@ -105,6 +105,13 @@ my @tests = ( count_on => 1, count_off => 1, }, + { + data => "string1, ,integer1\nFoo,Bar,123", + option => undef, + error => qr\Empty field name\, + count_on => 1, + count_off => 1, + }, { data => "string1\nString content", option => 'dry_run', @@ -228,7 +235,14 @@ foreach my $test (@tests) my $test_name = defined $test->{option} ? "with option $test->{option} set to $status" : "with no options"; is($records->count, 0, "No records before import for test $test_name"); - $import->process; + + try { $import->process; }; + if ($test->{error}) + { + like($@, $test->{error}, "Got expected import error"); + next; + } + $records->clear; is($records->count, $test->{"count_$status"}, "Correct record count on import for test $test_name");