diff --git a/C4/Koha.pm b/C4/Koha.pm index 0776ebcbc4..ec561a08e3 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -742,13 +742,28 @@ sub _normalize_match_point { sub _isbn_cleanup { my ($isbn) = @_; - return NormalizeISBN( - { - isbn => $isbn, - format => 'ISBN-10', - strip_hyphens => 1, - } - ) if $isbn; + + return unless $isbn; + + if ( $isbn =~ /^979/ ) { + + # ISBNs starting with 979 cannot be converted to ISBN-10 format, but all other valid ISBNs can + return NormalizeISBN( + { + isbn => $isbn, + format => 'ISBN-13', + strip_hyphens => 1, + } + ); + } else { + return NormalizeISBN( + { + isbn => $isbn, + format => 'ISBN-10', + strip_hyphens => 1, + } + ); + } } =head2 NormalizeISBN diff --git a/t/db_dependent/Koha.t b/t/db_dependent/Koha.t index a73738c940..47a9998610 100755 --- a/t/db_dependent/Koha.t +++ b/t/db_dependent/Koha.t @@ -173,7 +173,7 @@ subtest 'Authorized Values Tests' => sub { }; subtest 'isbn tests' => sub { - plan tests => 29; + plan tests => 33; my $isbn13 = "9780330356473"; my $isbn13D = "978-0-330-35647-3"; @@ -273,7 +273,11 @@ subtest 'isbn tests' => sub { 'Test GetNormalizedISBN' ); is( C4::Koha::GetNormalizedISBN('9781250067128 | 125006712X'), '125006712X', 'Test GetNormalizedISBN' ); - is( C4::Koha::GetNormalizedISBN('9780373211463 | 0373211465'), '0373211465', 'Test GetNormalizedISBN' ); + + my $test_normalized_isbn10 = C4::Koha::GetNormalizedISBN('9780373211463 | 0373211465'); + is( $test_normalized_isbn10, '0373211465', 'Test GetNormalizedISBN' ); + my $test_isbn10 = Business::ISBN->new($test_normalized_isbn10); + is( $test_isbn10->type, 'ISBN10', 'ISBN not starting with 979 is normalized to valid ISBN-10 format' ); is( C4::Koha::GetNormalizedUPC(), undef, 'GetNormalizedUPC should return undef if no record is passed' ); is( @@ -288,6 +292,13 @@ subtest 'isbn tests' => sub { C4::Koha::GetNormalizedOCLCNumber(), undef, 'GetNormalizedOCLCNumber should return undef if no record and no isbn are passed' ); + + is( C4::Koha::GetNormalizedISBN('979-8-88650-962-5'), '9798886509625', 'Test GetNormalizedISBN' ); + + my $test_normalized_isbn13 = C4::Koha::GetNormalizedISBN('9798886509625'); + is( $test_normalized_isbn13, '9798886509625', 'Test GetNormalizedISBN' ); + my $test_isbn13 = Business::ISBN->new($test_normalized_isbn13); + is( $test_isbn13->type, 'ISBN13', 'ISBN starting with 979 is normalized to valid ISBN-13 format' ); }; subtest 'issn stuff' => sub {