From: dbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Fri, 16 Apr 2010 04:38:02 +0000 (+0000)
Subject: Prevent possible character corruption or fatal errors in SRU / Z39.50
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f971ccabc076b382969c296ed52e1871ca0c62c8;p=evergreen%2Fmasslnc.git

Prevent possible character corruption or fatal errors in SRU / Z39.50

All MARC records in the Evergreen database are Unicode-encoded. However,
if the LDR09 hasn't been updated to indicate this, when we invoke
MARC::File::XML->as_xml_record it automatically runs a MARC8-to-UTF8 conversion
over the data - potentially corrupting the data, or resulting in fatal
errors. When holdings are added to records in SRU / Z39.50, we invoke
this code path.

The solution here is to simply manually set the leader 09 position to 'a'
before invoking MARC::File::XML->as_xml_record.


git-svn-id: svn://svn.open-ils.org/ILS/trunk@16247 dcc99617-32d9-48b4-a31d-7c20da2025e4
---

diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm
index 95d0249a14..356908debb 100644
--- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm
+++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm
@@ -1739,7 +1739,7 @@ sub sru_search {
 			'open-ils.search.biblio.multiclass.query' => {offset => $offset, limit => $limit} => $search_string => 1
 		)->gather(1);
 
-        my $bre = $supercat->request( 'open-ils.supercat.record.object.retrieve' => [ map { $_->[0] } @{$recs->{ids}} ] )->gather(1);
+		my $bre = $supercat->request( 'open-ils.supercat.record.object.retrieve' => [ map { $_->[0] } @{$recs->{ids}} ] )->gather(1);
 
 		foreach my $record (@$bre) {
 			my $marcxml = $record->marc;
@@ -1750,6 +1750,13 @@ sub sru_search {
 				my $bib_holdings = $supercat->request('open-ils.supercat.record.basic_holdings.retrieve', $record->id, $shortname || '-')->gather(1);
 				my $marc = MARC::Record->new_from_xml($marcxml, 'UTF8', 'XML');
 
+				# Force record leader to 'a' as our data is always UTF8
+				# Avoids marc8_to_utf8 from being invoked with horrible results
+				# on the off-chance the record leader isn't correct
+				my $ldr = $marc->leader;
+				substr($ldr, 9, 1, 'a');
+				$marc->leader($ldr);
+
 				# Expects the record ID in the 001
 				$marc->delete_field($_) for ($marc->field('001'));
 				if (!$marc->field('001')) {
@@ -1797,9 +1804,9 @@ sub sru_search {
 			);
 		}
 
-        $resp->numberOfRecords($recs->{count});
+		$resp->numberOfRecords($recs->{count});
 
-    } elsif ( $resp->type eq 'explain' ) {
+	} elsif ( $resp->type eq 'explain' ) {
 		if (!$ex_doc) {
 			my $host = $cgi->virtual_host || $cgi->server_name;
 
@@ -1864,9 +1871,9 @@ sub sru_search {
 		);
 	}
 
-   	print $cgi->header( -type => 'application/xml' );
-   	print $U->entityize($resp->asXML) . "\n";
-    return Apache2::Const::OK;
+	print $cgi->header( -type => 'application/xml' );
+	print $U->entityize($resp->asXML) . "\n";
+	return Apache2::Const::OK;
 }