From a5278786fb1c0de82c5727c8a841ed3cb1258cf7 Mon Sep 17 00:00:00 2001 From: Petro Vashchuk Date: Sun, 3 Apr 2022 00:02:40 +0300 Subject: [PATCH] Bug 30409: barcodedecode() should always trim barcode Barcode is trimmed of leading/trailing whitespaces in many instances before the barcodedecode sub was called. This patch instead makes that barcodedecode sub is going to trim it itself and removes unnecessary, and repetitive code that was used before barcodedecode was called. --- C4/Circulation.pm | 2 ++ circ/circulation.pl | 1 - circ/renew.pl | 1 - circ/returns.pl | 1 - .../prog/en/modules/admin/preferences/circulation.pref | 2 +- 5 files changed, 3 insertions(+), 4 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index c6baf4892f..fdda0bcc59 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -153,6 +153,7 @@ Will do some manipulation of the barcode for systems that deliver a barcode to circulation.pl that differs from the barcode stored for the item. For proper functioning of this filter, calling the function on the correct barcode string (items.barcode) should return an unaltered barcode. +Barcode is going to be automatically trimmed of leading/trailing whitespaces. The optional $filter argument is to allow for testing or explicit behavior that ignores the System Pref. Valid values are the same as the @@ -166,6 +167,7 @@ System Pref options. sub barcodedecode { my ($barcode, $filter) = @_; my $branch = C4::Context::mybranch(); + $barcode =~ s/^\s+|\s+$//g; $filter = C4::Context->preference('itemBarcodeInputFilter') unless $filter; Koha::Plugins->call('item_barcode_transform', \$barcode ); $filter or return $barcode; # ensure filter is defined, else return untouched barcode diff --git a/circ/circulation.pl b/circ/circulation.pl index ac8ef1e430..c876e41e93 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -159,7 +159,6 @@ if (C4::Context->preference("DisplayClearScreenButton")) { } for my $barcode ( @$barcodes ) { - $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace $barcode = barcodedecode( $barcode ) if $barcode; } diff --git a/circ/renew.pl b/circ/renew.pl index 97b6317067..41c6afe48c 100755 --- a/circ/renew.pl +++ b/circ/renew.pl @@ -43,7 +43,6 @@ my $schema = Koha::Database->new()->schema(); my $barcode = $cgi->param('barcode') // ''; my $unseen = $cgi->param('unseen') || 0; -$barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespae $barcode = barcodedecode($barcode) if $barcode; my $override_limit = $cgi->param('override_limit'); my $override_holds = $cgi->param('override_holds'); diff --git a/circ/returns.pl b/circ/returns.pl index f98907187a..84b5248230 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -119,7 +119,6 @@ foreach ( $query->param ) { $counter++; # decode barcode ## Didn't we already decode them before passing them back last time?? - $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace $barcode = barcodedecode($barcode) if $barcode; ###################### diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 3e81898de6..555077f144 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -35,7 +35,7 @@ Circulation: T-prefix: Remove the first number from T-prefix style libsuite8: Convert from Libsuite8 form EAN13: EAN-13 or zero-padded UPC-A form - - scanned item barcodes. + - scanned item barcodes. Mind that barcode always trimmed from both ends before this filter. - - pref: itemBarcodeFallbackSearch choices: -- 2.31.1