From 6744cd6612be7a8ac60db45d2fdce6f303bb2122 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 17 Nov 2022 10:02:08 +0000 Subject: [PATCH] Bug 24606: (QA follow-up) Fix encoding/decoding We should use OO interface and leave encoding to database layer. Test plan: Add a new item template containing real Unicode chars. Save. Apply on new item. Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- Koha/Item/Template.pm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Koha/Item/Template.pm b/Koha/Item/Template.pm index d6d0555a9e..8adf9ea125 100644 --- a/Koha/Item/Template.pm +++ b/Koha/Item/Template.pm @@ -41,7 +41,7 @@ sub store { my ($self) = @_; if ( ref( $self->contents ) eq 'HASH' ) { - $self->contents( encode_json( $self->contents ) ); + $self->contents( $self->_json->encode( $self->contents ) ); } $self = $self->SUPER::store; @@ -56,11 +56,20 @@ Returns a deserilized perl structure of the JSON formatted contents sub decoded_contents { my ($self) = @_; - return decode_json( encode_utf8($self->contents) ) if $self->contents; + return $self->_json->decode($self->contents) if $self->contents; } =head2 Internal methods +=head3 _json + +=cut + +sub _json { + my $self = shift; + $self->{_json} //= JSON->new; # Keep utf8 off ! +} + =head3 _type =cut -- 2.39.5