Bug 27045: Fix items lost report export if delimiter is tab

When choosing tabulation as the delimiter for a CSV profile
for the lost item report, the tabs appear in the file as \t
instead of as proper tabs.

title\tauthor\tstocknumber\tcallnumber
"E Street shuffle :"\"Heylin, Clinton."\\

To test:
* Upate the existing sample lost item CSV profile to use tabs as
  separator
* Make sure you have some lost items in your database or create some
* Go to Reports > Lost items
* Run the report
* Check all or some of the checkboxes in the result list
* Export using the link on top and the CSV profile
* Verify the tabs are not exported correctly
* Apply patch
* Verify tabs now are proper tabs instead of \t

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 983965ee47)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 4db8368fd5)
Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com>
This commit is contained in:
Jonathan Druart 2020-11-20 15:33:02 +01:00 committed by Arthur Suzuki
parent 0c2f6c9f43
commit becbc5bec1
1 changed files with 9 additions and 5 deletions

View File

@ -31,7 +31,7 @@ use CGI qw ( -utf8 );
use Text::CSV_XS;
use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers );
use Text::CSV::Encoded;
use Koha::AuthorisedValues;
use Koha::CsvProfiles;
@ -60,7 +60,6 @@ if ( $op eq 'export' ) {
my $csv_profile = Koha::CsvProfiles->find( $csv_profile_id );
die "There is no valid csv profile given" unless $csv_profile;
my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->csv_separator,'binary'=>1});
my $csv_profile_content = $csv_profile->content;
my ( @headers, @fields );
while ( $csv_profile_content =~ /
@ -89,11 +88,16 @@ if ( $op eq 'export' ) {
}
push @rows, \@row;
}
my $content = join( $csv_profile->csv_separator, @headers ) . "\n";
my $delimiter = $csv_profile->csv_separator;
$delimiter = "\t" if $delimiter eq "\\t";
my $csv = Text::CSV::Encoded->new({ encoding_out => 'UTF-8', sep_char => $delimiter});
$csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag();
$csv->combine(@headers);
my $content .= Encode::decode('UTF-8', $csv->string()) . "\n";
for my $row ( @rows ) {
$csv->combine(@$row);
my $string = $csv->string;
$content .= $string . "\n";
$content .= $csv->string . "\n";
}
print $query->header(
-type => 'text/csv',