From ca040f198a67a975b9e2445483cd932626a9eba0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 16 Oct 2019 10:47:28 +0200 Subject: [PATCH] Bug 17359: Correct encoding when displaying patron import summary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is an encoding issue when the patron import summry, the string must be UTF8 decoded before being sent to the template. Test plan: - Create a patron import CSV file with import issues. Use UTF8 characters. See file attached to the bug report 'patron_import.csv' => The screen should display the line correctly - Correct the import issue (add a surname for Chloé) => The imported patrons should contain the correct values. Signed-off-by: Séverine QUEUNE --- Koha/Patrons/Import.pm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm index 3575b8a..cb3ba56 100644 --- a/Koha/Patrons/Import.pm +++ b/Koha/Patrons/Import.pm @@ -21,6 +21,7 @@ use namespace::clean; use Carp; use Text::CSV; +use Encode qw( decode_utf8 ); use C4::Members; use C4::Members::Attributes qw(:all); @@ -101,7 +102,7 @@ sub import_patrons { my $status = $self->text_csv->parse($borrowerline); my @columns = $self->text_csv->fields(); if ( !$status ) { - push @missing_criticals, { badparse => 1, line => $line_number, lineraw => $borrowerline }; + push @missing_criticals, { badparse => 1, line => $line_number, lineraw => decode_utf8($borrowerline) }; } elsif ( @columns == @columnkeys ) { @borrower{@columnkeys} = @columns; @@ -125,7 +126,7 @@ sub import_patrons { elsif ( scalar grep { $key eq $_ } @criticals ) { # a critical field is undefined - push @missing_criticals, { key => $key, line => $., lineraw => $borrowerline }; + push @missing_criticals, { key => $key, line => $., lineraw => decode_utf8($borrowerline) }; } else { $borrower{$key} = ''; @@ -483,14 +484,14 @@ sub check_branch_code { # No branch code unless( $branchcode ) { - push (@$missing_criticals, { key => 'branchcode', line => $line_number, lineraw => $borrowerline, }); + push (@$missing_criticals, { key => 'branchcode', line => $line_number, lineraw => decode_utf8($borrowerline), }); return; } # look for branch code my $library = Koha::Libraries->find( $branchcode ); unless( $library ) { - push (@$missing_criticals, { key => 'branchcode', line => $line_number, lineraw => $borrowerline, + push (@$missing_criticals, { key => 'branchcode', line => $line_number, lineraw => decode_utf8($borrowerline), value => $branchcode, branch_map => 1, }); } } @@ -508,14 +509,14 @@ sub check_borrower_category { # No branch code unless( $categorycode ) { - push (@$missing_criticals, { key => 'categorycode', line => $line_number, lineraw => $borrowerline, }); + push (@$missing_criticals, { key => 'categorycode', line => $line_number, lineraw => decode_utf8($borrowerline), }); return; } # Looking for borrower category my $category = Koha::Patron::Categories->find($categorycode); unless( $category ) { - push (@$missing_criticals, { key => 'categorycode', line => $line_number, lineraw => $borrowerline, + push (@$missing_criticals, { key => 'categorycode', line => $line_number, lineraw => decode_utf8($borrowerline), value => $categorycode, category_map => 1, }); } } @@ -540,7 +541,7 @@ sub format_dates { $params->{borrower}->{$date_type} = $formatted_date; } else { $params->{borrower}->{$date_type} = ''; - push (@{$params->{missing_criticals}}, { key => $date_type, line => $params->{line}, lineraw => $params->{lineraw}, bad_date => 1 }); + push (@{$params->{missing_criticals}}, { key => $date_type, line => $params->{line}, lineraw => decode_utf8($params->{lineraw}), bad_date => 1 }); } } } -- 2.1.4