From 647a986b617124377dfab0a761a134300c75c7f8 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=utf8 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 Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize (cherry picked from commit 5b03d4be39497be0dbdce17ef26867ca80affec1) Signed-off-by: Fridolin Somers --- 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 b18db0d7ad..e32b33f9c9 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} = ''; @@ -467,14 +468,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, }); } } @@ -492,14 +493,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, }); } } @@ -524,7 +525,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.39.5