Bugzilla – Attachment 106110 Details for
Bug 25774
REST API searches don't handle correctly utf8 characters
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25774: Handle utf8 chars in REST API queries
Bug-25774-Handle-utf8-chars-in-REST-API-queries.patch (text/plain), 3.67 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-06-19 19:47:34 UTC
(
hide
)
Description:
Bug 25774: Handle utf8 chars in REST API queries
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-06-19 19:47:34 UTC
Size:
3.67 KB
patch
obsolete
>From 3ef6a948c1338e0e71028c0955709dd8afb1d267 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 17 Jun 2020 09:43:40 +0200 >Subject: [PATCH] Bug 25774: Handle utf8 chars in REST API queries >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >We must utf8 encode the string before json decoding it. > >Test plan: >Use "â¤" and play with the library search (bug 25288) and Postman to >generate queries using it. > >This patch prevents 500: >[2020/06/16 14:11:37] [ERROR] GET /api/v1/libraries: unhandled exception (Mojo::Exception)<<Wide character in subroutine entry at /kohadevbox/koha/Koha/REST/Plugin/Objects.pm line 107.>> Koha::REST::Plugin::Exceptions::__ANON__ /kohadevbox/koha/Koha/REST/Plugin/Exceptions.pm (73) > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/REST/Plugin/Objects.pm | 7 ++++--- > t/db_dependent/Koha/REST/Plugin/Objects.t | 24 +++++++++++++++++++++-- > 2 files changed, 26 insertions(+), 5 deletions(-) > >diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm >index 81cc97633c8..f4e8be227fe 100644 >--- a/Koha/REST/Plugin/Objects.pm >+++ b/Koha/REST/Plugin/Objects.pm >@@ -19,7 +19,7 @@ use Modern::Perl; > > use Mojo::Base 'Mojolicious::Plugin'; > >-use JSON qw(decode_json); >+use JSON; > > =head1 NAME > >@@ -104,8 +104,9 @@ sub register { > my @query_params_array; > my $query_params; > push @query_params_array, $reserved_params->{query} if defined $reserved_params->{query}; >- push @query_params_array, decode_json($reserved_params->{q}) if defined $reserved_params->{q}; >- push @query_params_array, decode_json($reserved_params->{'x-koha-query'}) if defined $reserved_params->{'x-koha-query'}; >+ my $json = JSON->new; >+ push @query_params_array, $json->decode($reserved_params->{q}) if defined $reserved_params->{q}; >+ push @query_params_array, $json->decode($reserved_params->{'x-koha-query'}) if defined $reserved_params->{'x-koha-query'}; > > if(scalar(@query_params_array) > 1) { > $query_params = {'-and' => \@query_params_array}; >diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t >index 1d726ce7081..5a2b207c64c 100644 >--- a/t/db_dependent/Koha/REST/Plugin/Objects.t >+++ b/t/db_dependent/Koha/REST/Plugin/Objects.t >@@ -77,7 +77,7 @@ get '/biblios' => sub { > > > # The tests >-use Test::More tests => 9; >+use Test::More tests => 10; > use Test::Mojo; > > use t::lib::TestBuilder; >@@ -206,6 +206,26 @@ subtest 'objects.search helper, sorting on mapped column' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'objects.search helper, encoding' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ Koha::Cities->delete; >+ >+ $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'A', city_country => 'Argentina' } }); >+ $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'B', city_country => 'â¤Argentinaâ¤' } }); >+ >+ $t->get_ok('/cities?q={"country": "â¤Argentinaâ¤"}') >+ ->status_is(200) >+ ->json_has('/0') >+ ->json_hasnt('/1') >+ ->json_is('/0/name' => 'B'); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'objects.search helper, embed' => sub { > > plan tests => 2; >@@ -363,4 +383,4 @@ subtest 'object.search helper order by embedded columns' => sub { > ->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second'); > > $schema->storage->txn_begin; >-} >\ No newline at end of file >+} >-- >2.27.0
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 25774
:
105920
|
105930
|
105932
|
105935
|
106109
| 106110