From 7fff9ec6d55cd3bb81d4f87fbc56519ac9c2a725 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Fri, 14 Mar 2014 16:07:11 +0100
Subject: [PATCH] Bug 11944: replace uri_escape with uri_escape_utf8
 everywhere
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

To reproduce, edit, index notice with صة and search "صة"
---
 C4/Auth.pm                            |    2 +-
 C4/Search.pm                          |   22 +++++++++++-----------
 authorities/authorities-home.pl       |    2 +-
 cataloguing/addbiblio.pl              |    2 +-
 cataloguing/additem.pl                |    2 +-
 members/pay.pl                        |    2 +-
 reports/guided_reports.pl             |    2 +-
 reserve/renewscript.pl                |    2 +-
 serials/routing-preview.pl            |    2 +-
 serials/routing.pl                    |    2 +-
 serials/subscription-frequency.pl     |    2 +-
 serials/subscription-numberpattern.pl |    2 +-
 12 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/C4/Auth.pm b/C4/Auth.pm
index d0bc7bc..af5a8bb 100644
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -1809,7 +1809,7 @@ sub SetSearchHistorySession {
     return () unless $sessionID;
     my $session = get_session($sessionID);
     return () unless $session;
-    $session->param('search_history', uri_escape(encode_json($search_history)));
+    $session->param('search_history', uri_escape_utf8(encode_json($search_history)));
 }
 
 END { }    # module clean-up code here (global destructor)
diff --git a/C4/Search.pm b/C4/Search.pm
index 56eca2f..c2e9d9a 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -1306,17 +1306,17 @@ sub buildQuery {
         if ( @limits ) {
             $q .= ' and '.join(' and ', @limits);
         }
-        return ( undef, $q, $q, "q=ccl=".uri_escape($q), $q, '', '', '', '', 'ccl' );
+        return ( undef, $q, $q, "q=ccl=".uri_escape_utf8($q), $q, '', '', '', '', 'ccl' );
     }
     if ( $query =~ /^cql=/ ) {
-        return ( undef, $', $', "q=cql=".uri_escape($'), $', '', '', '', '', 'cql' );
+        return ( undef, $', $', "q=cql=".uri_escape_utf8($'), $', '', '', '', '', 'cql' );
     }
     if ( $query =~ /^pqf=/ ) {
         if ($query_desc) {
-            $query_cgi = "q=".uri_escape($query_desc);
+            $query_cgi = "q=".uri_escape_utf8($query_desc);
         } else {
             $query_desc = $';
-            $query_cgi = "q=pqf=".uri_escape($');
+            $query_cgi = "q=pqf=".uri_escape_utf8($');
         }
         return ( undef, $', $', $query_cgi, $query_desc, '', '', '', '', 'pqf' );
     }
@@ -1488,9 +1488,9 @@ sub buildQuery {
                         $query     .= " $operators[$i-1] ";
                         $query     .= " $index_plus " unless $indexes_set;
                         $query     .= " $operand";
-                        $query_cgi .= "&op=".uri_escape($operators[$i-1]);
-                        $query_cgi .= "&idx=".uri_escape($index) if $index;
-                        $query_cgi .= "&q=".uri_escape($operands[$i]) if $operands[$i];
+                        $query_cgi .= "&op=".uri_escape_utf8($operators[$i-1]);
+                        $query_cgi .= "&idx=".uri_escape_utf8($index) if $index;
+                        $query_cgi .= "&q=".uri_escape_utf8($operands[$i]) if $operands[$i];
                         $query_desc .=
                           " $operators[$i-1] $index_plus $operands[$i]";
                     }
@@ -1500,8 +1500,8 @@ sub buildQuery {
                         $query      .= " and ";
                         $query      .= "$index_plus " unless $indexes_set;
                         $query      .= "$operand";
-                        $query_cgi  .= "&op=and&idx=".uri_escape($index) if $index;
-                        $query_cgi  .= "&q=".uri_escape($operands[$i]) if $operands[$i];
+                        $query_cgi  .= "&op=and&idx=".uri_escape_utf8($index) if $index;
+                        $query_cgi  .= "&q=".uri_escape_utf8($operands[$i]) if $operands[$i];
                         $query_desc .= " and $index_plus $operands[$i]";
                     }
                 }
@@ -1513,8 +1513,8 @@ sub buildQuery {
                     $query .= " $index_plus " unless $indexes_set;
                     $query .= $operand;
                     $query_desc .= " $index_plus $operands[$i]";
-                    $query_cgi  .= "&idx=".uri_escape($index) if $index;
-                    $query_cgi  .= "&q=".uri_escape($operands[$i]) if $operands[$i];
+                    $query_cgi  .= "&idx=".uri_escape_utf8($index) if $index;
+                    $query_cgi  .= "&q=".uri_escape_utf8($operands[$i]) if $operands[$i];
                     $previous_operand = 1;
                 }
             }    #/if $operands
diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl
index 3c9fefd..121adf0 100755
--- a/authorities/authorities-home.pl
+++ b/authorities/authorities-home.pl
@@ -125,7 +125,7 @@ if ( $op eq "do_search" ) {
     # next/previous would not work anymore
 
     # construction of the url of each page
-    my $value_url = uri_escape($value);
+    my $value_url = uri_escape_utf8($value);
     my $base_url = "authorities-home.pl?"
       ."marclist=$marclist"
       ."&amp;and_or=$and_or"
diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl
index fa3e90b..de15c0b 100755
--- a/cataloguing/addbiblio.pl
+++ b/cataloguing/addbiblio.pl
@@ -886,7 +886,7 @@ if ( $op eq "addbiblio" ) {
             .'&frameworkcode='.$frameworkcode
             .'&circborrowernumber='.$fa_circborrowernumber
             .'&branch='.$fa_branch
-            .'&barcode='.uri_escape($fa_barcode)
+            .'&barcode='.uri_escape_utf8($fa_barcode)
             .'&stickyduedate='.$fa_stickyduedate
             .'&duedatespec='.$fa_duedatespec
 		);
diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index 8dc5e30..9a57b4d 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -515,7 +515,7 @@ if ($op eq "additem") {
         print $input->redirect(
            '/cgi-bin/koha/circ/circulation.pl?'
            .'borrowernumber='.$fa_circborrowernumber
-           .'&barcode='.uri_escape($fa_barcode)
+           .'&barcode='.uri_escape_utf8($fa_barcode)
            .'&duedatespec='.$fa_duedatespec
            .'&stickyduedate=1'
         );
diff --git a/members/pay.pl b/members/pay.pl
index 6665989..2fedfa3 100755
--- a/members/pay.pl
+++ b/members/pay.pl
@@ -171,7 +171,7 @@ sub redirect_to_paycollect {
     $redirect .= get_for_redirect( 'notify_id',    "notify_id$line_no",    0 );
     $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
     $redirect .= get_for_redirect( 'accountlines_id', "accountlines_id$line_no", 0 );
-    $redirect .= q{&} . 'payment_note' . q{=} . uri_escape( $input->param("payment_note_$line_no") );
+    $redirect .= q{&} . 'payment_note' . q{=} . uri_escape_utf8( $input->param("payment_note_$line_no") );
     $redirect .= '&remote_user=';
     $redirect .= $user;
     return print $input->redirect($redirect);
diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl
index 4d41e1a..89b019b 100755
--- a/reports/guided_reports.pl
+++ b/reports/guided_reports.pl
@@ -743,7 +743,7 @@ elsif ($phase eq 'Run this report'){
             my $totpages = int($total/$limit) + (($total % $limit) > 0 ? 1 : 0);
             my $url = "/cgi-bin/koha/reports/guided_reports.pl?reports=$report_id&amp;phase=Run%20this%20report&amp;limit=$limit";
             if (@sql_params) {
-                $url = join('&amp;sql_params=', $url, map { URI::Escape::uri_escape($_) } @sql_params);
+                $url = join('&amp;sql_params=', $url, map { URI::Escape::uri_escape_utf8($_) } @sql_params);
             }
             $template->param(
                 'results' => \@rows,
diff --git a/reserve/renewscript.pl b/reserve/renewscript.pl
index 43e9082..7b93cd9 100755
--- a/reserve/renewscript.pl
+++ b/reserve/renewscript.pl
@@ -127,7 +127,7 @@ foreach my $barcode (@barcodes) {
 # redirection to the referrer page
 #
 if ( $input->param('destination') eq "circ" ) {
-    $cardnumber = uri_escape($cardnumber);
+    $cardnumber = uri_escape_utf8($cardnumber);
     print $input->redirect( '/cgi-bin/koha/circ/circulation.pl?findborrower='
           . $cardnumber
           . $failedrenews
diff --git a/serials/routing-preview.pl b/serials/routing-preview.pl
index 8b899cf..6d08bf2 100755
--- a/serials/routing-preview.pl
+++ b/serials/routing-preview.pl
@@ -133,7 +133,7 @@ $routingnotes =~ s/\n/\<br \/\>/g;
 $template->param(
     title => $subs->{'bibliotitle'},
     issue => $issue,
-    issue_escaped => URI::Escape::uri_escape($issue),
+    issue_escaped => URI::Escape::uri_escape_utf8($issue),
     subscriptionid => $subscriptionid,
     memberloop => $memberloop,
     routingnotes => $routingnotes,
diff --git a/serials/routing.pl b/serials/routing.pl
index 4232127..f508cf9 100755
--- a/serials/routing.pl
+++ b/serials/routing.pl
@@ -62,7 +62,7 @@ if($op eq 'add'){
 if($op eq 'save'){
     my $sth = $dbh->prepare('UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?');
     $sth->execute($notes,$subscriptionid);
-    my $urldate = URI::Escape::uri_escape($date_selected);
+    my $urldate = URI::Escape::uri_escape_utf8($date_selected);
     print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$urldate");
 }
 
diff --git a/serials/subscription-frequency.pl b/serials/subscription-frequency.pl
index c32692a..6d3b7e1 100755
--- a/serials/subscription-frequency.pl
+++ b/serials/subscription-frequency.pl
@@ -33,4 +33,4 @@ if ($auth_status ne "ok") {
 my $frequencyrecord=GetSubscriptionFrequency($frqid);
 binmode STDOUT, ":encoding(UTF-8)";
 print $input->header(-type => 'text/plain', -charset => 'UTF-8');
-print "{".join (",",map { "\"$_\":\"".uri_escape($frequencyrecord->{$_})."\"" }sort keys %$frequencyrecord)."}";
+print "{".join (",",map { "\"$_\":\"".uri_escape_utf8($frequencyrecord->{$_})."\"" }sort keys %$frequencyrecord)."}";
diff --git a/serials/subscription-numberpattern.pl b/serials/subscription-numberpattern.pl
index b0b0ae1..cf0fdfa 100755
--- a/serials/subscription-numberpattern.pl
+++ b/serials/subscription-numberpattern.pl
@@ -36,4 +36,4 @@ my $numpatternid=$input->param("numberpattern_id");
 my $numberpatternrecord=GetSubscriptionNumberpattern($numpatternid);
 binmode STDOUT, ":encoding(UTF-8)";
 print $input->header(-type => 'text/plain', -charset => 'UTF-8');
-print "{",join (",",map {"\"$_\":\"".(uri_escape($numberpatternrecord->{$_}) // '')."\"" }sort keys %$numberpatternrecord),"}";
+print "{",join (",",map {"\"$_\":\"".(uri_escape_utf8($numberpatternrecord->{$_}) // '')."\"" }sort keys %$numberpatternrecord),"}";
-- 
1.7.10.4