[Koha-patches] [PATCH] UTF8 double encoding fixes. Commits squashed into one.

Srdjan srdjan at catalyst.net.nz
Mon Sep 30 07:31:36 CEST 2013


From: Ketan Kulkarni <ketan at carvingit.com>

double utf8 encoding fix .. second try

minor formatting updates

enhancement to the previous patch related to utf8 double encoding

added ENCODING=>utf8 to new->

added space which is there in master

added utf8::decode for ms_query

replaced tabs with spaces

replaced tabs with spaces

removed extra space

Signed-off-by: Srdjan <srdjan at catalyst.net.nz>

http://bugs.koha-community.org/show_bug.cgi?id=6554
---
 C4/ItemType.pm      | 4 ++--
 C4/Search.pm        | 2 ++
 C4/Templates.pm     | 7 ++++---
 members/member.pl   | 3 +++
 opac/opac-search.pl | 1 +
 5 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/C4/ItemType.pm b/C4/ItemType.pm
index ad253a7..4aa23d4 100644
--- a/C4/ItemType.pm
+++ b/C4/ItemType.pm
@@ -81,7 +81,7 @@ sub all {
     for ( @{$dbh->selectall_arrayref(
         "SELECT * FROM itemtypes ORDER BY description", { Slice => {} })} )
     {
-        utf8::encode($_->{description});
+        utf8::upgrade($_->{description});
         push @itypes, $class->new($_);
     }
     return @itypes;
@@ -105,7 +105,7 @@ sub get {
         "SELECT * FROM itemtypes WHERE itemtype = ?", undef, $itemtype
     );
     if ( $data->{description} ) {
-        utf8::encode($data->{description});
+        utf8::upgrade($data->{description});
     }
     return $class->new($data);
 }
diff --git a/C4/Search.pm b/C4/Search.pm
index 0453b91..1180746 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -574,6 +574,7 @@ sub getRecords {
                             {
 
 # Sanitize the link value : parenthesis, question and exclamation mark will cause errors with CCL
+                                utf8::decode($one_facet);
                                 my $facet_link_value = $one_facet;
                                 $facet_link_value =~ s/[()!?¡¿؟]/ /g;
 
@@ -1606,6 +1607,7 @@ sub buildQuery {
         warn "LIMIT DESC:" . $limit_desc;
         warn "---------\nLeave buildQuery\n---------";
     }
+    utf8::decode($query_desc);
     return (
         undef,              $query, $simple_query, $query_cgi,
         $query_desc,        $limit, $limit_cgi,    $limit_desc,
diff --git a/C4/Templates.pm b/C4/Templates.pm
index 21604fc..51a9df5 100644
--- a/C4/Templates.pm
+++ b/C4/Templates.pm
@@ -62,6 +62,7 @@ sub new {
     my $template = Template->new(
         {   EVAL_PERL    => 1,
             ABSOLUTE     => 1,
+            ENCODING => 'utf8',
             PLUGIN_BASE => 'Koha::Template::Plugin',
             COMPILE_EXT => C4::Context->config('template_cache_dir')?'.ttc':'',
             COMPILE_DIR => C4::Context->config('template_cache_dir')?C4::Context->config('template_cache_dir'):'',,
@@ -124,7 +125,7 @@ sub output {
             utf8_hashref($vars->{$k});
         }
         else {
-            utf8::encode($vars->{$k}) if utf8::is_utf8($vars->{$k});
+            utf8::upgrade($vars->{$k}) if utf8::is_utf8($vars->{$k});
         }
     }
     my $data;
@@ -145,7 +146,7 @@ sub utf8_arrayref {
             utf8_hashref($element);
             next;
         }
-        utf8::encode($element) if utf8::is_utf8($element);
+        utf8::upgrade($element) if utf8::is_utf8($element);
     }        
 }         
 
@@ -160,7 +161,7 @@ sub utf8_hashref {
             utf8_hashref($hashref->{$key});
             next;
         }
-        utf8::encode($hashref->{$key}) if utf8::is_utf8($hashref->{$key});
+        utf8::upgrade($hashref->{$key}) if utf8::is_utf8($hashref->{$key});
     }
 }
         
diff --git a/members/member.pl b/members/member.pl
index 78b762f..a30b01b 100755
--- a/members/member.pl
+++ b/members/member.pl
@@ -49,6 +49,9 @@ my ($template, $loggedinuser, $cookie)
 my $theme = $input->param('theme') || "default";
 
 my $patron = $input->Vars;
+my $tmp_member = $patron->{member};
+utf8::decode($tmp_member);
+$patron->{member} = $tmp_member;
 foreach (keys %$patron){
 	delete $$patron{$_} unless($$patron{$_});
 }
diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index 2854da6..664285f 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -395,6 +395,7 @@ $template->{VARS}->{querystring} = join(' ', @operands);
 if ($operands[0] && !$operands[1]) {
     my $ms_query = $operands[0];
     $ms_query =~ s/ #\S+//;
+    utf8::decode($ms_query);
     $template->param(ms_value => $ms_query);
 }
 
-- 
1.8.1.2


More information about the Koha-patches mailing list