Re: Encoding in Mason components

James Orr <[email protected]> Thu, 14 Aug 2014 10:29:16 -0400
Newsgroups gmane.comp.web.mason.user
Message-ID <CAFWVHUHrcdA7nBRV8_aJR+NTg0qiXiNn54h=doHvGyr64_feZw@mail.gmail.com>
--===============3037629539343151504==
Content-Type: multipart/alternative; boundary=047d7bd75df2bb9803050097bae1

--047d7bd75df2bb9803050097bae1
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

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' =3D> sub {
my $orig =3D shift;
my $self =3D shift;

my %params =3D @_;
while (my($key, $value) =3D each(%params)) {
while (my ($k, $v) =3D each(%$value)) {
$params{$key}->{$k} =3D decode_utf8($v);
}
}
$self->$orig(%params);
};

On Wed, Aug 13, 2014 at 8:19 AM, Jonathan Swartz <[email protected]> wrote:

> Ladislav - you can find some starting points here =E2=80=94
>
> http://stackoverflow.com/questions/5858596/how-to-make-mason2-utf-8-clean
>
> https://www.mail-archive.com/[email protected]/msg03450.h=
tml
>
> There ought to be a Mason::Plugin::Utf8 that handles this, but I never ha=
d
> the time and it appears no one else did either=E2=80=A6 :)
>
> Best
> Jon
>
> On Aug 13, 2014, at 5:13 AM, Adam Sj=C3=B8gren <[email protected]> wrote:
>
> Ladislav Laska <[email protected]> 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.po=
d#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=C3=
=B8gren
>                                                         [email protected]
>
>
>
> -------------------------------------------------------------------------=
-----
> _______________________________________________
> Mason-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mason-users
>
>
>
>
> -------------------------------------------------------------------------=
-----
>
> _______________________________________________
> Mason-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mason-users
>
>

--047d7bd75df2bb9803050097bae1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I had some utf8 issues as well, I used the plugin at the s=
tackoverflow link which worked for the most part, except any parameters pas=
sed in to a page were getting double encoded.<div><br></div><div>I made thi=
s change to the around &#39;run&#39; in Mason::Plugin::UTF8::Request which =
seems to fix the problem ...</div>
<div><br></div><div><div class=3D"gmail_extra"><div class=3D"gmail_extra">a=
round &#39;run&#39; =3D&gt; sub {</div><div class=3D"gmail_extra"><span cla=
ss=3D"" style=3D"white-space:pre">	</span>my $orig =3D shift;</div><div cla=
ss=3D"gmail_extra">
<span class=3D"" style=3D"white-space:pre">	</span>my $self =3D shift;</div=
><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra"><span clas=
s=3D"" style=3D"white-space:pre">	</span>my %params =3D @_;</div><div class=
=3D"gmail_extra">
<span class=3D"" style=3D"white-space:pre">	</span>while (my($key, $value) =
=3D each(%params)) {</div><div class=3D"gmail_extra"><span class=3D"" style=
=3D"white-space:pre">		</span>while (my ($k, $v) =3D each(%$value)) {</div>=
<div class=3D"gmail_extra">
<span class=3D"" style=3D"white-space:pre">			</span>$params{$key}-&gt;{$k}=
 =3D decode_utf8($v);</div><div class=3D"gmail_extra"><span class=3D"" styl=
e=3D"white-space:pre">		</span>}</div><div class=3D"gmail_extra"><span clas=
s=3D"" style=3D"white-space:pre">	</span>}</div>
<div class=3D"gmail_extra"><span class=3D"" style=3D"white-space:pre">	</sp=
an>$self-&gt;$orig(%params);</div><div class=3D"gmail_extra">};</div><br><d=
iv class=3D"gmail_quote">On Wed, Aug 13, 2014 at 8:19 AM, Jonathan Swartz <=
span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_blank">=
[email protected]</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><div style=3D"word-wrap:break-word"><div>Ladislav - you ca=
n find some starting points here =E2=80=94</div>
<div><br></div><div><a href=3D"http://stackoverflow.com/questions/5858596/h=
ow-to-make-mason2-utf-8-clean" target=3D"_blank">http://stackoverflow.com/q=
uestions/5858596/how-to-make-mason2-utf-8-clean</a></div><div><a href=3D"ht=
tps://www.mail-archive.com/[email protected]/msg03450.html"=
 target=3D"_blank">https://www.mail-archive.com/[email protected]=
ge.net/msg03450.html</a></div>
<div><br></div><div>There ought to be a Mason::Plugin::Utf8 that handles th=
is, but I never had the time and it appears no one else did either=E2=80=A6=
 :)</div><div><br></div><div>Best</div><div>Jon</div><div><div class=3D"h5"=
><br><div>
<div>On Aug 13, 2014, at 5:13 AM, Adam Sj=C3=B8gren &lt;<a href=3D"mailto:a=
[email protected]" target=3D"_blank">[email protected]</a>&gt; wrote:</div><=
br><blockquote type=3D"cite">Ladislav Laska &lt;<a href=3D"mailto:laska@kam=
.mff.cuni.cz" target=3D"_blank">[email protected]</a>&gt; writes:<br>
<br><blockquote type=3D"cite">So my question to the community is: what is t=
he right way to do it?<br></blockquote><br>In the old HTML::Mason (1) days,=
 I would put &#39;use utf8;&#39; in the preamble<br>parameter:<br><br> * <a=
 href=3D"https://metacpan.org/pod/distribution/HTML-Mason/lib/HTML/Mason/Pa=
rams.pod#preamble" target=3D"_blank">https://metacpan.org/pod/distribution/=
HTML-Mason/lib/HTML/Mason/Params.pod#preamble</a><br>
<br><br>I don&#39;t know if Mason (2) has changed anything in this regard.<=
br><br><br> =C2=A0Best regards,<br><br> =C2=A0=C2=A0=C2=A0Adam<br><br>-- <b=
r> &quot;Repetition is the death of magic.&quot; =C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Adam Sj=C3=B8gren<br> =
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<a href=3D"mailto:[email protected]" ta=
rget=3D"_blank">[email protected]</a><br>
<br><br>-------------------------------------------------------------------=
-----------<br>_______________________________________________<br>Mason-use=
rs mailing list<br><a href=3D"mailto:[email protected]" tar=
get=3D"_blank">[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/mason-users" target=
=3D"_blank">https://lists.sourceforge.net/lists/listinfo/mason-users</a><br=
></blockquote></div><br></div></div></div><br>-----------------------------=
-------------------------------------------------<br>

<br>_______________________________________________<br>
Mason-users mailing list<br>
<a href=3D"mailto:[email protected]">[email protected]=
ceforge.net</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/mason-users" target=
=3D"_blank">https://lists.sourceforge.net/lists/listinfo/mason-users</a><br=
>
<br></blockquote></div><br></div></div></div>

--047d7bd75df2bb9803050097bae1--


--===============3037629539343151504==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------

--===============3037629539343151504==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users

--===============3037629539343151504==--