This code looks wrong to me.  I don't think that utf8 line should be there.

sub freeze {
    my ( $self, @args ) = @_;
    my $json = JSON::Any->objToJson( $self->pack(@args) );
    utf8::decode($json) if !utf8::is_utf8($json) and
utf8::valid($json); # if it's valid utf8 mark it as such
    return $json;
}


Normally, I would want to take a structure that might include character
data (i.e utf8 flag is on) and serialize it into (utf8) encoded bytes.   So
JSON::Any->objToJson does that.    In other words:

my %utf8_char = ( foo => 'hello ' . "\N{U+263A}" );
my $return_trip = JSON::Any->jsonToObj( JSON::Any->objToJson( \%utf8_char )
);
print Encode::is_utf8( $return_trip->{foo} ) ? "Yes utf8\n" : "Nope, not
ut8\n";


Works as expected:

Yes utf8


So, the "freeze" method quoted above first returns the utf8-encoded string
then does this:

    utf8::decode($json) if !utf8::is_utf8($json) and
utf8::valid($json); # if it's valid utf8 mark it as such


turns the string back into utf8 characters.

As a result when I send that frozen serialized string some place I get Wide
Character errors.



-- 
Bill Moseley
mose...@hank.org

Reply via email to