@@ -, +, @@ --- Koha/REST/Plugin/Objects.pm | 5 +++-- t/db_dependent/Koha/REST/Plugin/Objects.t | 24 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) --- a/Koha/REST/Plugin/Objects.pm +++ a/Koha/REST/Plugin/Objects.pm @@ -20,6 +20,7 @@ use Modern::Perl; use Mojo::Base 'Mojolicious::Plugin'; use JSON qw(decode_json); +use Encode qw(encode_utf8); =head1 NAME @@ -104,8 +105,8 @@ 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'}; + push @query_params_array, decode_json(encode_utf8 $reserved_params->{q}) if defined $reserved_params->{q}; + push @query_params_array, decode_json(encode_utf8 $reserved_params->{'x-koha-query'}) if defined $reserved_params->{'x-koha-query'}; if(scalar(@query_params_array) > 1) { $query_params = {'-and' => \@query_params_array}; --- a/t/db_dependent/Koha/REST/Plugin/Objects.t +++ a/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?country=❤') + ->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; -} +} --