From 666ec454734c66844f8fbdef22bb2dd48075f235 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 7 Jan 2022 15:34:49 -1000 Subject: [PATCH] Bug 29826: Manage call of Template Plugin Branches GetName() with null or empty branchcode Bug 26587 added a concatenation that sends a warning if var is undef : $ prove t/db_dependent/Template/Plugin/Branches.t Use of uninitialized value $branchcode in concatenation (.) or string at /kohadevbox/koha/Koha/Template/Plugin/Branches.pm line 35. This patch adds an early return empty string when GetName is called with $branchcode null or empty string. Test plan : 1) Run t/db_dependent/Template/Plugin/Branches.t without patch 2) Run with the patch to see warning disappear Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- Koha/Template/Plugin/Branches.pm | 2 ++ t/db_dependent/Template/Plugin/Branches.t | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm index 2cdb1be81d..981c5b413d 100644 --- a/Koha/Template/Plugin/Branches.pm +++ b/Koha/Template/Plugin/Branches.pm @@ -30,6 +30,8 @@ use Koha::Libraries; sub GetName { my ( $self, $branchcode ) = @_; + return q{} unless defined $branchcode; + return q{} if $branchcode eq q{}; my $memory_cache = Koha::Cache::Memory::Lite->get_instance; my $cache_key = "Library_branchname:" . $branchcode; diff --git a/t/db_dependent/Template/Plugin/Branches.t b/t/db_dependent/Template/Plugin/Branches.t index 3957887525..a1145d6693 100755 --- a/t/db_dependent/Template/Plugin/Branches.t +++ b/t/db_dependent/Template/Plugin/Branches.t @@ -38,7 +38,7 @@ my $builder = t::lib::TestBuilder->new; subtest 'all() tests' => sub { - plan tests => 18; + plan tests => 19; $schema->storage->txn_begin; @@ -68,6 +68,9 @@ subtest 'all() tests' => sub { $name = $plugin->GetName(undef); is($name, '', 'received empty string as name of NULL/undefined library code'); + $name = $plugin->GetName(q{}); + is($name, '', 'received empty string as name of empty string library code'); + is($plugin->GetLoggedInBranchcode(), '', 'no active library code if there is no active user session'); is($plugin->GetLoggedInBranchname(), '', 'no active library name if there is no active user session'); -- 2.39.5