From 9be2740e319e370887556234ee403d9152ab8060 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 16 Nov 2018 09:30:56 +0100 Subject: [PATCH] Bug 21848: Handle encoding when calling Text::Unaccent::unac_string Content-Type: text/plain; charset=utf-8 Resolve warnings like: unac_string: Invalid or incomplete multibyte or wide character Note that Text::Unaccent says: Return the unaccented equivalent of the string $string. The character set of $string is specified by the $charset argument. The returned string is coded using the same character set. The only place we call unac_string is: Koha::Patron->generate_userid: $userid = unac_string('utf-8',$userid); Since we say to unac_string that $userid is utf-8, we should first encode it and the result we should decode again for further handling. Test plan: [1] Run t/db_dependent/Koha/Patrons.t [2] Run t/db_dependent/Circulation.t (before this patch it gave a few warns) Signed-off-by: Marcel de Rooy --- Koha/Patron.pm | 3 ++- t/db_dependent/Koha/Patrons.t | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 5831034..7e4ba46 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -21,6 +21,7 @@ package Koha::Patron; use Modern::Perl; use Carp; +use Encode qw/encode_utf8 decode_utf8/; use List::MoreUtils qw( uniq ); use JSON qw( to_json ); use Text::Unaccent qw( unac_string ); @@ -1313,7 +1314,7 @@ sub generate_userid { $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; my $userid = lc(($firstname)? "$firstname.$surname" : $surname); - $userid = unac_string('utf-8',$userid); + $userid = decode_utf8(unac_string('utf-8',encode_utf8($userid))); $userid .= $offset unless $offset == 0; $self->userid( $userid ); $offset++; diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index c552220..52a407d 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -18,6 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; +use utf8; use Test::More tests => 34; use Test::Warn; @@ -1389,8 +1390,8 @@ subtest 'generate_userid' => sub { ); my %data = ( cardnumber => "123456789", - firstname => "Tomasito", - surname => "None", + firstname => "Tomasíto", # accent + surname => "Ñòñé", # accents categorycode => $patron_category->categorycode, branchcode => $library->branchcode, ); -- 2.1.4