From 8bc4409773b3f955ab3dac80689eeea0bccddc2b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 11 Nov 2022 15:26:39 -0300 Subject: [PATCH] Bug 24606: Fix encoding issues on decoded content This patch makes the `decoded_contents` method UTF-8 encode the data before calling the relevant decode_json, as expected by the JSON library [1]. To test: 1. Apply the regression tests patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Item/Template.t => FAIL: Tests fail! 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! [1] `Any decoding or encoding (e.g. to UTF-8 or UTF-16) needs to be done yourself, e.g. using the Encode module.` https://metacpan.org/pod/JSON Signed-off-by: Tomas Cohen Arazi --- Koha/Item/Template.pm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Koha/Item/Template.pm b/Koha/Item/Template.pm index b2e04a57d23..d6d0555a9ec 100644 --- a/Koha/Item/Template.pm +++ b/Koha/Item/Template.pm @@ -17,7 +17,8 @@ package Koha::Item::Template; use Modern::Perl; -use JSON qw( encode_json decode_json ); +use Encode qw(encode_utf8); +use JSON qw(encode_json decode_json); use base qw(Koha::Object); @@ -27,7 +28,7 @@ Koha::Item::Template - Koha Item Template Object class =head1 API -=head2 Class Methods +=head2 Class methods =head3 store @@ -55,10 +56,12 @@ Returns a deserilized perl structure of the JSON formatted contents sub decoded_contents { my ($self) = @_; - return decode_json( $self->contents ) if $self->contents; + return decode_json( encode_utf8($self->contents) ) if $self->contents; } -=head3 type +=head2 Internal methods + +=head3 _type =cut -- 2.38.1