From 5674fc0d905bb59a4e9bb2a4683b35742c68234a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 17 Apr 2013 10:47:58 -0300 Subject: [PATCH] Bug 10068 - Replace the utf8 pragma at C4/Search.pm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit utf8::decode($string) for Encode::decode('UTF-8',$string) Added Carp and error handling. Sponsored-by: Universidad Nacional de Córdoba --- C4/Search.pm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index d4ce9fb..aff9b24 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -31,6 +31,8 @@ use C4::Branch; use C4::Reserves; # GetReserveStatus use C4::Debug; use C4::Charset; +use Carp; +use Encode; use YAML; use URI::Escape; use Business::ISBN; @@ -484,7 +486,8 @@ sub getRecords { # not an index scan else { $record = $results[ $i - 1 ]->record($j)->raw(); - utf8::decode( $record ); + eval { $record = decode( 'UTF-8', $record, Encode::FB_CROAK ); } ; + if ( $@ ) { carp "Error decoding $record: $@" }; # warn "RECORD $j:".$record; $results_hash->{'RECORDS'}[$j] = $record; @@ -502,7 +505,10 @@ sub getRecords { for ( my $j = 0 ; $j < $jmax ; $j++ ) { my $render_record = $results[ $i - 1 ]->record($j)->render(); - utf8::decode($render_record); + eval { $render_record = decode( 'UTF-8', $render_record, + Encode::FB_CROAK); }; + if ( $@ ) { carp "Error decoding $render_record: $@" }; + my @used_datas = (); foreach my $tag ( @{ $facet->{tags} } ) { @@ -716,7 +722,8 @@ sub pazGetRecords { for (my $i = 0; $i < $count; $i++) { # FIXME -- may need to worry about diacritics here my $rec = $paz->record($recid, $i); - utf8::decode( $rec ); + eval { $rec = decode( 'UTF-8', $rec, Encode::FB_CROAK ); }; + if ( $@ ) { carp "Error decoding $rec: $@" }; push @{ $result_group->{'RECORDS'} }, $rec; } @@ -1751,7 +1758,10 @@ sub searchResults { my $subfieldvalue = $repl[$i]; if (! utf8::is_utf8($subfieldvalue)) { - utf8::decode($subfieldvalue); + eval { + $subfieldvalue = decode('UTF-8',$subfieldvalue, + Encode::FB_CROAK); }; + if ( $@ ) { carp "Error decoding $subfieldvalue: $@" }; } $newline =~ s/\[$tag\]/$subfieldvalue/g; -- 1.7.10.4