From 40e73740f44e9dfa228d5b68ee4b2feb4b1b33eb Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Thu, 21 Nov 2019 16:03:48 +0000 Subject: [PATCH] Bug 17979: Fatal error when searching from addbooks.pl due to ISBN flaw This patch adds true ISBN detection to cataloging searches so that ISBNs can be correctly identified and passed to queries of the reservoir. To test, apply the patch and go to Cataloging. - In the "Cataloging search" form at the top of the page, test various searches to confirm that results are returned in both the catalog and the reservoir: - Any title search - A search for a title which begins with a numeral, e.g. "1st to die" - A search by 10-digit ISBN - A search by 13-digit ISBN --- cataloguing/addbooks.pl | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/cataloguing/addbooks.pl b/cataloguing/addbooks.pl index 20829138621..b658c11b0bf 100755 --- a/cataloguing/addbooks.pl +++ b/cataloguing/addbooks.pl @@ -85,7 +85,6 @@ if ($query) { if ( defined $error ) { $template->param( error => $error ); - warn "error: " . $error; output_html_with_http_headers $input, $cookie, $template->output; exit; } @@ -110,18 +109,14 @@ if ($query) { my $countbr = 0; my @resultsbr; if ($query) { -# fill isbn or title, depending on what has been entered -#u must do check on isbn because u can find number in beginning of title -#check is on isbn legnth 13 for new isbn and 10 for old isbn + # fill isbn or title, depending on what has been entered + #u must do check on isbn because u can find number in beginning of title my ( $title, $isbn ); - if ($query=~/\d/) { - my $clean_query = $query; - $clean_query =~ s/-//g; # remove hyphens - my $querylength = length $clean_query; - if ( $querylength == 13 || $querylength == 10 ) { - $isbn = $query; - } + if( $isbn = Business::ISBN->new( $query ) ) { + $isbn = $isbn->as_isbn10->as_string; + $isbn =~ s/-//g; } + if (!$isbn) { $title = $query; } -- 2.11.0