From 19b07172837fad73cb64b87f94b0e7f41a86d7bf Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 4 Jul 2016 11:53:39 +0100 Subject: [PATCH] Bug 16848: Prevent invalid warning to be carped from output_pref From Koha::DateUtils::output_pref: $dt = eval { dt_from_string( $str ) } if $str; carp "Invalid date '$str' passed to output_pref\n" if $@; This second line is wrong: if $str does not exist, the first line is not evaluated and $@ could be filled with previous error. To reproduce: Then: prove t/DateUtils.t will display: t/DateUtils.t .. 20/60 Use of uninitialized value $str in concatenation (.) or string at Koha/DateUtils.pm line 217. Invalid date '' passed to output_pref at t/DateUtils.t line 233. t/DateUtils.t .. ok All tests successful. Files=1, Tests=60, 2 wallclock secs ( 0.02 usr 0.00 sys + 1.40 cusr 0.00 csys = 1.42 CPU) Result: PASS Test plan: Without this patch, you should not see the carp --- Koha/DateUtils.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index 6207cc1..b486942 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -213,8 +213,10 @@ sub output_pref { and return if $dt and $str; - $dt = eval { dt_from_string( $str ) } if $str; - carp "Invalid date '$str' passed to output_pref\n" if $@; + if ( $str ) { + $dt = eval { dt_from_string( $str ) }; + carp "Invalid date '$str' passed to output_pref\n" if $@; + } return unless defined $dt; -- 2.8.1