From bab05ebda3badfd59495995fb4683fd946ff3a5e Mon Sep 17 00:00:00 2001 From: Petter Goksoyr Asen Date: Wed, 16 Jul 2014 09:52:50 +0200 Subject: [PATCH] Bug 12581 - Fix encoding issues in /svc/bib endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating a record by sending a POST request with the MARCXML data Koha's /svc/bib endpoint can result in mangled characters in the saved record. By contrast, the /svc/new_bib endpoint, for creating a new record, correctly fixes theese encoding issues. This patch replicates the fix from svc/new_bib to svc/bib. Test plan * Update a record by sending MARCXML to the /svc/bib endpoint. The record should contain non-latin characters, for example æ,ø, å. * Observe that the returned response, and the record in the database has mangled characters. * Apply the patch * Repeat the first step * Observe that the record now is free from encoding errors. --- svc/bib | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/svc/bib b/svc/bib index 8f6a168..5b2e273 100755 --- a/svc/bib +++ b/svc/bib @@ -27,6 +27,7 @@ use C4::Auth qw/check_api_auth/; use C4::Biblio; use C4::Items; use XML::Simple; +use C4::Charset; my $query = new CGI; binmode STDOUT, ':encoding(UTF-8)'; @@ -82,12 +83,19 @@ sub update_bib { my $inxml = $query->param('POSTDATA'); print $query->header(-type => 'text/xml'); - my $record = eval {MARC::Record::new_from_xml( $inxml, "utf8", C4::Context->preference('marcflavour'))}; + my $marcflavour = C4::Context->preference('marcflavour'); + my $record = eval {MARC::Record::new_from_xml( $inxml, "utf8", $marcflavour)}; my $do_not_escape = 0; if ($@) { $result->{'status'} = "failed"; $result->{'error'} = $@; } else { + # fix character set + if ($record->encoding() eq 'MARC-8') { + my ($guessed_charset, $charset_errors); + ($record, $guessed_charset, $charset_errors) = MarcToUTF8Record($record, $marcflavour); + } + my $fullrecord = $record->clone(); my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", '' ); -- 1.8.3.2