From 55f3881b74922ae323c5ec3e97da5cf53463c9e7 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 16 Sep 2016 09:39:15 +0200 Subject: [PATCH] [PASSED QA] Bug 17302: [Follow-up] Make Normalize.pm undef-resistent Trivial changes for passing undef to the norm routines. Added a few dumb tests too. Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer --- Koha/Util/Normalize.pm | 16 +++++++++++----- t/Koha/Util/Normalize.t | 20 +++++++++++++++++++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Koha/Util/Normalize.pm b/Koha/Util/Normalize.pm index 487d5da..a654c3f 100644 --- a/Koha/Util/Normalize.pm +++ b/Koha/Util/Normalize.pm @@ -41,8 +41,10 @@ Default normalization function =cut sub legacy_default { + my ( $string ) = @_; + return if !defined( $string ); - my $string = uc shift; + $string = uc $string; $string =~ s/[.;:,\]\[\)\(\/'"]//g; $string =~ s/^\s+//; @@ -59,8 +61,8 @@ Normalization function removing spaces =cut sub remove_spaces { - - my $string = shift; + my ( $string ) = @_; + return if !defined( $string ); $string =~ s/\s+//g; @@ -74,8 +76,10 @@ Normalization function converting characters into upper-case =cut sub upper_case { + my ( $string ) = @_; + return if !defined( $string ); - my $string = uc shift; + $string = uc $string; return $string; } @@ -87,8 +91,10 @@ Normalization function converting characters into lower-case =cut sub lower_case { + my ( $string ) = @_; + return if !defined( $string ); - my $string = lc shift; + $string = lc $string; return $string; } diff --git a/t/Koha/Util/Normalize.t b/t/Koha/Util/Normalize.t index 9ebdf06..7480c23 100644 --- a/t/Koha/Util/Normalize.t +++ b/t/Koha/Util/Normalize.t @@ -17,12 +17,30 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; +use Test::Warn; BEGIN { use_ok('Koha::Util::Normalize'); } +subtest 'pass undef' => sub { + plan tests => 8; + + is( legacy_default(), undef, 'legacy_default returns undef' ); + warning_is { legacy_default() } undef, 'no warn from legacy_default'; + + is( remove_spaces(), undef, 'remove_spaces returns undef' ); + warning_is { remove_spaces() } undef, 'no warn from remove_spaces'; + + is( upper_case(), undef, 'upper_case returns undef' ); + warning_is { upper_case() } undef, 'no warn from upper_case'; + + is( lower_case(), undef, 'lower_case returns undef' ); + warning_is { lower_case() } undef, 'no warn from lower_case'; +}; + + subtest 'legacy_default() normalizer' => sub { plan tests => 1; -- 2.7.4