From cdda11af2f411a1fad7e2d571b94af80523fa2ba Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Wed, 9 Jul 2014 16:34:26 -0400 Subject: [PATCH] LP#1302207 - Attempt to validate ISBNs in AddedContent.pm. When getting ISBNs from the database, they often contain extra stuff after the ISBN that sometimes causes problems for Business::ISBN. This commit attempts to resolve some of that by looking only for the part of the ISBN data that resembles an ISBN and using just that part. If the ISBN data doesn't look like an ISBN, then it is discarded. Signed-off-by: Jason Stephenson Signed-off-by: Ben Shum --- .../perlmods/lib/OpenILS/WWW/AddedContent.pm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent.pm index 276dcc92bf..e2adf6d3b7 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent.pm @@ -143,10 +143,19 @@ sub handler { my @upcs = grep {$_->{tag} eq '024'} @$key_data; map { - my $isbn_obj = Business::ISBN->new($_->{value}); - my $isbn_str; - $isbn_str = $isbn_obj->as_string([]) if defined($isbn_obj); - $_->{value} = $isbn_str; + # Attempt to validate the ISBN. + # strip out hyphens; + $_->{value} =~ s/-//g; + #pull out the first chunk that looks like an ISBN: + if ($_->{value} =~ /([0-9xX]{10}(?:[0-9xX]{3})?)/) { + $_->{value} = $1; + my $isbn_obj = Business::ISBN->new($_->{value}); + my $isbn_str; + $isbn_str = $isbn_obj->as_string([]) if defined($isbn_obj); + $_->{value} = $isbn_str; + } else { + undef $_->{value}; + } undef $_ if !defined($_->{value}); } @isbns; -- 2.43.2