From a3a3a24e98d7d44a67e8c1b05e13821c574aebd3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 26 Feb 2014 13:15:54 +0100 Subject: [PATCH] Bug 11679: FIX encoding in CSV file Previously, the CSV file was not in encoded in utf8 and the csv2ods command failed with the following error if diacritics existed: UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 Signed-off-by: Aurelie Fichot --- reports/guided_reports.pl | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index 394fadf..491df41 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -19,7 +19,7 @@ use CGI qw/-utf8/; -use Text::CSV; +use Text::CSV::Encoded; use URI::Escape; use File::Temp; use C4::Reports::Guided; @@ -772,7 +772,6 @@ elsif ($phase eq 'Run this report'){ } elsif ($phase eq 'Export'){ - binmode STDOUT, ':encoding(UTF-8)'; # export results to tab separated text or CSV my $sql = $input->param('sql'); # FIXME: use sql from saved report ID#, not new user-supplied SQL! @@ -789,8 +788,8 @@ elsif ($phase eq 'Export'){ } else { my $delimiter = C4::Context->preference('delimiter') || ','; my $csv_content = q||; - my $csv = Text::CSV->new({binary => 1, sep_char => $delimiter}); - $csv or die "Text::CSV->new({binary => 1}) FAILED: " . Text::CSV->error_diag(); + my $csv = Text::CSV::Encoded->new({ encoding_out => 'utf8', sep_char => $delimiter}); + $csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag(); if ($csv->combine(header_cell_values($sth))) { $csv_content .= $csv->string(). "\n"; } else { -- 1.7.2.5