Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the TMDB CPAN distribution.

Report information
The Basics
Id: 85530
Status: resolved
Priority: 0/
Queue: TMDB

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.061
Fixed in: (no value)



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
On Tue May 21 21:13:20 2013, david wrote: Show quoted text
> 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
Fixed in 0.07. Thanks for the bug report -Mithun