From: Jason Stephenson Date: Wed, 9 Jul 2014 20:34:26 +0000 (-0400) Subject: LP#1302207 - Attempt to validate ISBNs in AddedContent.pm. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=cdda11af2f411a1fad7e2d571b94af80523fa2ba;p=evergreen%2Fpines.git 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 --- 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;