From 80b7104e58952b2c08cddee0e365b6a92dde3662 Mon Sep 17 00:00:00 2001 From: Blou Date: Mon, 28 Feb 2022 12:12:38 -0500 Subject: [PATCH] Bug 30196: Odd number of elements warning caused by dt_from_string Koha/DateUtils' dt_from_string is a sub expected to return a scalar, but does not in all case. In one instance, tt simply return... nothing, which cause one common call output_pref( { dt => dt_from_string( $serinfo->{$d} ), dateonly => 1 } ); to output a warning. Simply returning undef instead will solve the issue. Test plan: 1- Have a terminal tail intranet error logs 2- In the code, go to about.pl and change the only dt_from_string() to dt_from_string('0000-00-00') 3- Go to About Koha 4- Notice the logs output is: "Odd number of elements in anonymous hash at ..." and error 500 on the page. 5- Apply the patch 6- Redo step 3 and notice the previous log output is not there and the page loads 7- run `prove t/DateUtils.t` and all tests should pass --- Koha/DateUtils.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index 2ee889aac5..7d3be8d3f6 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -58,7 +58,7 @@ to the system preferences. If the date string is empty DateTime->now is returned sub dt_from_string { my ( $date_string, $date_format, $tz ) = @_; - return if $date_string and $date_string =~ m|^0000-0|; + return undef if $date_string and $date_string =~ m|^0000-0|; my $do_fallback = defined($date_format) ? 0 : 1; my $server_tz = C4::Context->tz; -- 2.25.1