kohabug 2022 - fixed fine and issuing rules editors

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

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
Galen Charlton 2008-04-18 13:09:19 -05:00 committed by Joshua Ferraro
parent f47bebfeb6
commit 579a227228
3 changed files with 56 additions and 10 deletions

View File

@ -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__

View File

@ -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,
);

View File

@ -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,
);