From 369d73ea82218256b20337236e27e7511a86ab1e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 9 Aug 2019 10:47:17 +0000 Subject: [PATCH] Bug 23324:(QA follow-up) Use existing NormalizeISBN function --- C4/Koha.pm | 10 ++++++++-- Koha/Util/Normalize.pm | 14 ++++++++------ t/Koha.t | 4 +++- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index a150809..3743f7f 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -836,7 +836,9 @@ sub _isbn_cleanup { to be of the specified format. If the string cannot be validated as an isbn, - it returns nothing. + it returns nothing unless return_invalid param is passed. + + #FIXME This routine (and others?) should be moved to Koha::Util::Normalize =cut @@ -846,6 +848,7 @@ sub NormalizeISBN { my $string = $params->{isbn}; my $strip_hyphens = $params->{strip_hyphens}; my $format = $params->{format}; + my $return_invalid = $params->{return_invalid}; return unless $string; @@ -854,7 +857,7 @@ sub NormalizeISBN { if ( $isbn && $isbn->is_valid() ) { if ( $format eq 'ISBN-10' ) { - $isbn = $isbn->as_isbn10(); + $isbn = $isbn->as_isbn10(); } elsif ( $format eq 'ISBN-13' ) { $isbn = $isbn->as_isbn13(); @@ -868,7 +871,10 @@ sub NormalizeISBN { } return $string; + } elsif ( $return_invalid ) { + return $string; } + } =head2 GetVariationsOfISBN diff --git a/Koha/Util/Normalize.pm b/Koha/Util/Normalize.pm index efe4839..7fe4179 100644 --- a/Koha/Util/Normalize.pm +++ b/Koha/Util/Normalize.pm @@ -112,12 +112,14 @@ sub ISBN { my ( $string ) = @_; return if !defined( $string ); - my $isbn = Business::ISBN->new($string); - if (defined $isbn && $isbn->is_valid) { - $string = $isbn->as_isbn13->as_string([]); - } - - return $string; + my $isbn = C4::Koha::NormalizeISBN({ + isbn => $string, + format => 'ISBN-13', + strip_hyphens => 1, + return_invalid => 1, + }); + + return $isbn; } 1; diff --git a/t/Koha.t b/t/Koha.t index b8d4346..9f794d4 100755 --- a/t/Koha.t +++ b/t/Koha.t @@ -25,7 +25,7 @@ use Module::Load::Conditional qw/check_install/; BEGIN { if ( check_install( module => 'Test::DBIx::Class' ) ) { - plan tests => 38; + plan tests => 39; } else { plan skip_all => "Need Test::DBIx::Class" } @@ -81,6 +81,8 @@ eval { $isbn = C4::Koha::NormalizeISBN({ isbn => '0788893777 (2 DVD 45th ed)', format => 'ISBN-10', strip_hyphens => 1 }); }; ok($@ eq '', 'NormalizeISBN does not throw exception when parsing invalid ISBN (bug 12243)'); +$isbn = C4::Koha::NormalizeISBN({ isbn => '0788893777 (2 DVD 45th ed)', format => 'ISBN-10', strip_hyphens => 1, return_invalid =>1 }); +is($isbn, '0788893777 (2 DVD 45th ed)', 'NormalizeISBN returns original string when converting to ISBN10 an ISBN starting with 979 (bug 13167)'); eval { $isbn = C4::Koha::NormalizeISBN({ isbn => '979-10-90085-00-8', format => 'ISBN-10', strip_hyphens => 1 }); -- 2.1.4