Subject: | UTF-8 encoded strings are incorrectly encoded |
The last statement in TMDB::Session::talk() says:
return $self->json->decode(
Encode::encode( 'utf-8-strict', $response->{content} ) )
; # Real Response
This is incorrect because HTTP::Tiny doesn't return back "decoded" strings--it returns raw byte strings. Running Encode::encode on a raw string ends up double encoding the non-ascii characters. If anything, I think you meant "Encode::decode" (it's super easy to get those backward) which takes a raw byte string and turns it into a wide character string. The problem with Encode::decode() is that JSON doesn't like getting wide characters in its input.
To fix this simply, remove the Encode::encode completely:
return $self->json->decode($response->{content}); # Real Response
That will just return back byte based strings.
If you want to return wide character strings from the API, then you need to decode:
return $self->json->decode(
Encode::decode( 'utf-8-strict', $response->{content} ) )
; # Real Response
and then set the utf-8 flag in JSON::Any:
json => {
type => OBJECT,
can => 'Load',
optional => 1,
default => JSON::Any->new(utf8 => 1),
},
-David