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 <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
923609f42e
commit
6744cd6612
1 changed files with 11 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue