Subject: | unicode double encoding caused by Plugin:Unicode::Encoding |
Plugin::Unicode::Encoding doesn't check for already encoded data before encoding it again :
from line 70:
# Encode expects plain scalars (IV, NV or PV) and segfaults on ref's
$c->response->body( $c->encoding->encode( $body, $CHECK ) )
if ref(\$body) eq 'SCALAR';
Naively only checks it's a scalar, not that it isn't already encoded, which will be the case if the body is JSON with unicode
Fix is :
# Encode expects plain scalars (IV, NV or PV) and segfaults on ref's
if (ref(\$body) eq 'SCALAR' && utf8::is_utf8($body)){
$c->response->body( $c->encoding->encode( $body, $CHECK ) );
}
In our case we have code in a controller which does :
$c->res->body(to_json($json, {
utf8 => 1,
pretty => defined $c->stash->{pretty_json}?$c->stash->{pretty_json}:1,
allow_blessed => 1,
convert_blessed => 1,
}));
This will always double encoded utf8 output without the patch shown