Bugzilla – Attachment 45432 Details for
Bug 15190
Bad utf8 decode to unapi and fixing code status 200
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15190: Bad utf8 decode to unapi and fixing blank screen error status
Bug-15190-Bad-utf8-decode-to-unapi-and-fixing-blan.patch (text/plain), 4.20 KB, created by
Marc Véron
on 2015-12-05 16:34:37 UTC
(
hide
)
Description:
Bug 15190: Bad utf8 decode to unapi and fixing blank screen error status
Filename:
MIME Type:
Creator:
Marc Véron
Created:
2015-12-05 16:34:37 UTC
Size:
4.20 KB
patch
obsolete
>From efa403bb2cde0ee5293ae2e347f57e76749718f4 Mon Sep 17 00:00:00 2001 >From: Hector Castro <hector.hecaxmmx@gmail.com> >Date: Fri, 13 Nov 2015 15:55:57 -0600 >Subject: [PATCH] Bug 15190: Bad utf8 decode to unapi and fixing blank screen > error status >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Fix bad utf8 decoding, also fix cgi->header(-status) to >redirect to one of the posible error pages in /cgi-bin/koha/errors/ > >To reproduce the issue in OPAC >1) Copy from LOC (Z39.50) ISBN 8467020113 or test it with whichever record with > special characters >2) Open URL in OPAC cgi-bin/koha/unapi?id=koha:biblionumber:4&format=oai_dc > play with oai_dc, srw_dc, mods, mods-full, mods3, mods3-full, rdfdc. > Note: marcxml does not fail >3) Enter the new biblionumber for ISBN 8467020113 or the record of your choise >4) An oai_dc record will display, notice about the bad utf8 > decoding characters >5) Search the record in OPAC >6) To reproduce blank screen (error status) play with: > cgi-bin/koha/unapi?id=koha:biblionumber:4&format= > cgi-bin/koha/unapi?id=koha:biblionumber:4&format=none > cgi-bin/koha/unapi?id=koha:biblionumber:&format=oai_dc > cgi-bin/koha/unapi?&format=oai_dc >7) If possible test in NORMARC (UNIMARC will launch an error because bug 15162) > >Test plan >-Apply patch >-Follow steps 2 to 6 >-You will see no errors in utf8 and redirection to one of the > error pages in /cgi-bin/koha/errors/ > >-- >Bad formatting reproduced e.g. with format=srw_dc, blank page reproduced with oai_dc, >after applying patch formatting and redirect to error page OK >Signed-off-by: Marc Véron <veron@veron.ch> >--- > opac/unapi | 22 +++++++++++++++------- > 1 file changed, 15 insertions(+), 7 deletions(-) > >diff --git a/opac/unapi b/opac/unapi >index 7b21ee0..a072423 100755 >--- a/opac/unapi >+++ b/opac/unapi >@@ -42,9 +42,9 @@ use C4::Context; > use C4::Biblio; > use XML::LibXML; > use XML::LibXSLT; >+use utf8; > > my $cgi = CGI->new(); >-binmode(STDOUT, ":encoding(UTF-8)"); #output as utf8 > > =head1 VARIABLES > >@@ -95,6 +95,12 @@ my $format_to_stylesheet_map = { > }, > }; > >+my %redirect_error = ( >+ 'error400' => '/cgi-bin/koha/errors/400.pl', >+ 'error404' => '/cgi-bin/koha/errors/404.pl', >+ 'error500' => '/cgi-bin/koha/errors/500.pl' >+ ); >+ > =head2 $format_info > > This hashref maps from unAPI output formats to the <format> elements >@@ -132,13 +138,14 @@ if (not defined $format) { > my $marcxml = GetXmlBiblio($biblionumber); > unless (defined $marcxml) { > # no bib, so 404 >- print $cgi->header( -status => '404 record not found'); >+ print $cgi->redirect( -uri => $redirect_error{error404} ); > exit 0; > } > > my $transformer = get_transformer($format, $format_to_stylesheet_map, $format_info); > unless (defined $transformer) { >- print $cgi->header( -status => '406 invalid format requested' ); >+ # invalid format requested >+ print $cgi->redirect( -uri => $redirect_error{error400} ); > exit 0; > } > my $parser = XML::LibXML->new(); >@@ -146,21 +153,22 @@ if (not defined $format) { > $record_dom = $transformer->transform( $record_dom ); > $content = $record_dom->toString(); > }; >- if ($@) { >- print $cgi->header( -status => '500 internal error ' . $@->code() . ": " . $@->message() ); >+ if ($@) { #$@->code(), $@->message() can't be passed to 500.pl >+ print $cgi->redirect( -uri => $redirect_error{error500} ); > exit 0; > } > > print $cgi->header( -type =>'application/xml' ); >+ utf8::decode($content); #output as utf8 > print $content; > } else { > # ID is obviously wrong, so 404 >- print $cgi->header( -status => '404 record not found'); >+ print $cgi->redirect( -uri => $redirect_error{error404} ); > exit 0; > } > } else { > # supplied a format but no id - caller is doing it wrong >- print $cgi->header( -status => '400 bad request - if you specify format, must specify id'); >+ print $cgi->redirect( -uri => $redirect_error{error404} ); > exit 0; > } > >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15190
:
44861
|
44887
|
45427
|
45428
|
45432
|
46513
|
46574
|
46581