From d673f068ce2b8d79cdcc4e59d560d6b9247539da 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 Signed-off-by: Kyle M Hall --- 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 8f82e0217a..680d4493a2 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