Bug 16848: Prevent invalid warning to be carped from output_pref
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 4 Jul 2016 10:53:39 +0000 (11:53 +0100)
committerFrédéric Demians <f.demians@tamil.fr>
Tue, 23 Aug 2016 09:50:05 +0000 (11:50 +0200)
commitf81c6770054dab1cb4b4a1ccea1b28bd702b412b
treef48a298e644638fee8411edd38ae7c2d5912c940
parenta42da0108e3f8dee889ef28e0c0d736e23a9aacc
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

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit c31213ba4fab0082c6ad556aae424918b62205d0)
Signed-off-by: Frédéric Demians <f.demians@tamil.fr>
Koha/DateUtils.pm