Another problem I had is that the $m->send_json method calls
JSON::XS::encode_json, which itself encodes the string as utf8, and this is
then getting double encoded by the after process_output call in the plugin.

I got around it by over-riding send_json and decoding the json string ...

around 'send_json' => sub {
my $orig = shift;
my $self = shift;
my $data = shift;
$self->clear_buffer;
my $result = JSON::XS::encode_json($data);
$self->print(decode_utf8(JSON::XS::encode_json($data)));
$self->res->content_type("application/json; charset=utf-8");
$self->abort();
};

Is there a better way to handle this?


On Thu, Aug 14, 2014 at 10:29 AM, James Orr <james.o...@gmail.com> wrote:

> I had some utf8 issues as well, I used the plugin at the stackoverflow
> link which worked for the most part, except any parameters passed in to a
> page were getting double encoded.
>
> I made this change to the around 'run' in Mason::Plugin::UTF8::Request
> which seems to fix the problem ...
>
> around 'run' => sub {
> my $orig = shift;
>  my $self = shift;
>
> my %params = @_;
>  while (my($key, $value) = each(%params)) {
> while (my ($k, $v) = each(%$value)) {
>  $params{$key}->{$k} = decode_utf8($v);
> }
> }
>  $self->$orig(%params);
> };
>
> On Wed, Aug 13, 2014 at 8:19 AM, Jonathan Swartz <swa...@pobox.com> wrote:
>
>> Ladislav - you can find some starting points here —
>>
>> http://stackoverflow.com/questions/5858596/how-to-make-mason2-utf-8-clean
>>
>> https://www.mail-archive.com/mason-users@lists.sourceforge.net/msg03450.html
>>
>> There ought to be a Mason::Plugin::Utf8 that handles this, but I never
>> had the time and it appears no one else did either… :)
>>
>> Best
>> Jon
>>
>> On Aug 13, 2014, at 5:13 AM, Adam Sjøgren <a...@koldfront.dk> wrote:
>>
>> Ladislav Laska <la...@kam.mff.cuni.cz> writes:
>>
>> So my question to the community is: what is the right way to do it?
>>
>>
>> In the old HTML::Mason (1) days, I would put 'use utf8;' in the preamble
>> parameter:
>>
>> *
>> https://metacpan.org/pod/distribution/HTML-Mason/lib/HTML/Mason/Params.pod#preamble
>>
>>
>> I don't know if Mason (2) has changed anything in this regard.
>>
>>
>>  Best regards,
>>
>>    Adam
>>
>> --
>> "Repetition is the death of magic."                          Adam Sjøgren
>>                                                         a...@koldfront.dk
>>
>>
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Mason-users mailing list
>> Mason-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/mason-users
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>>
>> _______________________________________________
>> Mason-users mailing list
>> Mason-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/mason-users
>>
>>
>
------------------------------------------------------------------------------
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to