[Koha-patches] [PATCH] kohabug 2022 - fixed fine and issuing rules editors

Galen Charlton galen.charlton at liblime.com
Fri Apr 18 20:09:19 CEST 2008


Because of the way that the older fine and issuing
rule editors generate the HTML form, if a branch code,
patron category code, or item type code happened to have a
'-' or '.', the HTML form would not be parsed properly, thus
adding an implicit (rather than explicit) limit on the
characters allowed in one of those codes.

This fix removes this limitation by Base64-encoding the codes
when constructing the names for the <input> elements.

Two functions are added to C4::Koha:

  str_to_base64() - UTF-8 string to Base64
  base64_to_str() - reverse
---
 C4/Koha.pm            |   44 ++++++++++++++++++++++++++++++++++++++++++++
 admin/finesrules.pl   |   11 ++++++-----
 admin/issuingrules.pl |   11 ++++++-----
 3 files changed, 56 insertions(+), 10 deletions(-)

diff --git a/C4/Koha.pm b/C4/Koha.pm
index d68cc96..31ffa37 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -21,6 +21,10 @@ package C4::Koha;
 use strict;
 use C4::Context;
 use C4::Output;
+
+use MIME::Base64 qw(encode_base64 decode_base64);
+use Encode qw(encode decode);
+
 use vars qw($VERSION @ISA @EXPORT $DEBUG);
 
 BEGIN {
@@ -50,6 +54,8 @@ BEGIN {
 		&GetKohaAuthorisedValues
 		&GetAuthValCode
 		&GetManagedTagSubfields
+        &str_to_base64
+        &base64_to_str
 
 		$DEBUG
 	);
@@ -920,6 +926,44 @@ ORDER BY marc_subfield_structure.tagfield, tagsubfield|);
   return $data;
 }
 
+=head2 str_to_base64
+
+=over 4
+
+my $base64 = str_to_base64($string_containing_unicode);
+
+=back
+
+Get a Base64 version of a string that is in UTF-8.  This
+function can be used to convert an arbitrary coded value
+(like a branch code) into a form that can be safely concatenated
+with similarly encoded values for a HTML form input name, as
+in admin/issuingrules.pl.
+
+=cut
+
+sub str_to_base64 {
+    my $in = shift;
+    return encode_base64(encode("UTF-8", $in), '');
+}
+
+=head2 base64_to_str
+
+=over 4
+
+my $base64 = base64_to_str($string_containing_unicode);
+
+=back
+
+Converse of C<str_to_base64()>.
+
+=cut
+
+sub base64_to_str {
+    my $in = shift;
+    return decode("UTF-8", decode_base64($in));
+}
+
 1;
 
 __END__
diff --git a/admin/finesrules.pl b/admin/finesrules.pl
index 3fea7f3..e89e7ad 100755
--- a/admin/finesrules.pl
+++ b/admin/finesrules.pl
@@ -55,10 +55,10 @@ if ($op eq 'save') {
 
   foreach my $key (@names){
     # FINES
-    if ($key =~ /F-(.*)-(.*)\.(.*)/) {
-      my $br = $1; # branch
-      my $bor = $2; # borrower category
-      my $cat = $3; # item type
+    if ($key =~ /F-(.*)-(.*)-(.*)/) {
+      my $br = base64_to_str($1); # branch
+      my $bor = base64_to_str($2); # borrower category
+      my $cat = base64_to_str($3); # item type
       my $data=$input->param($key);
       my ($fine,$firstremind,$chargeperiod)=split(',',$data);
       $bor="*" unless ($bor);
@@ -129,7 +129,8 @@ foreach my $data (@itemtypes) {
         $fine =~ s/\.*0*$//g;
         my $finesvalue;
         $finesvalue= "$fine,$dat->{'firstremind'},$dat->{'chargeperiod'}" if $fine ne '';
-        my %row = (finesname=> "F-$branch-$trow3[$i].$$data->{'itemtype'}",
+        my $finesname = join("-", "F", map { str_to_base64($_) } ($branch, $trow3[$i], $$data->{'itemtype'}));
+        my %row = (finesname=> $finesname,
                     finesvalue => $finesvalue,
                     toggle => $toggle,
                     );
diff --git a/admin/issuingrules.pl b/admin/issuingrules.pl
index d1a90c1..54d6b79 100755
--- a/admin/issuingrules.pl
+++ b/admin/issuingrules.pl
@@ -53,10 +53,10 @@ if ($op eq 'save') {
     my $sth_Idelete=$dbh->prepare("DELETE FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?");
     foreach my $key (@names){
         # ISSUES
-        if ($key =~ /I-(.*)-(.*)\.(.*)/) {
-            my $br = $1; # branch
-            my $bor = $2; # borrower category
-            my $cat = $3; # item type
+        if ($key =~ /I-(.*)-(.*)-(.*)/) {
+            my $br = base64_to_str($1); # branch
+            my $bor =  base64_to_str($2); # borrower category
+            my $cat =  base64_to_str($3); # item type
             my $data=$input->param($key);
             my ($issuelength,$maxissueqty,$rentaldiscount)=split(',',$data);
             if ($maxissueqty) {
@@ -131,7 +131,8 @@ foreach my $data (@itemtypes) {
         my $issuelength = $dat->{'issuelength'};
         my $issuingvalue;
         $issuingvalue = "$issuelength,$maxissueqty" if $maxissueqty ne '';
-        my %row = (issuingname => "I-$branch-$trow3[$i].$$data->{itemtype}",
+        my $issuingname = join("-", "I", map { str_to_base64($_) } ($branch, $trow3[$i], $$data->{itemtype}) );
+        my %row = (issuingname => $issuingname,
                     issuingvalue => $issuingvalue,
                     toggle => $toggle,
                     );
-- 
1.5.5.rc0.16.g02b00




More information about the Koha-patches mailing list