Bug 18536: Generating CSV using profile in serials late issues doesn't work as described
[koha.git] / serials / lateissues-export.pl
index d9fc473..ab524ea 100755 (executable)
@@ -45,14 +45,19 @@ my $csv = Text::CSV_XS->new({
 my $content = $csv_profile->{content};
 my ( @headers, @fields );
 while ( $content =~ /
-    ([^=]+) # header
-    =
-    ([^\|]+) # fieldname (table.row or row)
+    ([^=\|]+) # header
+    =?
+    ([^\|]*) # fieldname (table.row or row)
     \|? /gxms
 ) {
-    push @headers, $1;
-    my $field = $2;
-    $field =~ s/[^\.]*\.?//; # Remove the table name if exists.
+    my $header = $1;
+    my $field = ($2 eq '') ? $1 : $2;
+
+    $header =~ s/^\s+|\s+$//g; # Trim whitespaces
+    push @headers, $header;
+
+    $field =~ s/[^\.]*\.{1}//; # Remove the table name if exists.
+    $field =~ s/^\s+|\s+$//g; # Trim whitespaces
     push @fields, $field;
 }