[cgiapp] encoding pragma and CGI::Session

Mark Rajcok mrajcok at gmail.com
Mon Sep 27 23:37:15 EDT 2010


On Fri, Sep 3, 2010 at 8:31 PM, Ron Savage <ron at savage.net.au> wrote:

> Hi Todd
> Thanx for the sample code.
> More below.
>
> On Fri, 2010-09-03 at 09:08 -0700, Todd Ross wrote:
> > CGI::Session: 4.20
>
> Firstly, you can get V 4.42 from CPAN and V 4.45 from the repository.
> But, most importantly, I put a discussion of UTF8 in the docs:
>
>
> http://search.cpan.org/~markstos/CGI-Session-4.42/lib/CGI/Session.pm#A_Warning_about_UTF8<http://search.cpan.org/%7Emarkstos/CGI-Session-4.42/lib/CGI/Session.pm#A_Warning_about_UTF8>
>

Following the link I read this statement "Until this problem is understood
and corrected, users are advised to avoid UTF8 in conjunction with
CGI::Session".  Yikes!  Is it really that bad?  I'm using UTF-8 (everywhere
in my app) with CAP::Session without any problems  (although with a MySQL
backend for session storage, I did have to change the a_session field to a
"blob").

Todd, what was your intent with the   use encoding 'utf8';  line?  Do you
only want to save and restore UTF-8 encoded session data?  or do you want to
do that PLUS have Perl consider your script (i.e., file test.pl) to be
encoded in UTF-8?  I ask because I find this to be a common misunderstanding
about UTF-8.  The 'use encoding...' line is usually not what people should
use.  If you only want the script to read/write UTF-8, and your script is in
normal ASCII/ISO-8859-1 encoding, then try this instead of the 'use
encoding..' line to get the script to read and write UTF-8 on stdin and
stdout:
  binmode STDIN, ":encoding(utf8)";
  binmode STDOUT, ":encoding(utf8)";

With the above two lines, your script worked for me.

This might help: http://en.wikibooks.org/wiki/Perl_Programming/Unicode_UTF-8
(something I wrote a while ago when trying to understand how UTF-8 works).

-- Mark


> See also the discussions on RT:
> https://rt.cpan.org/Public/Bug/Display.html?id=21981
> https://rt.cpan.org/Public/Bug/Display.html?id=28516
> Naturally, if can help us resolve this problem, we'd all be delighted.
>
> --
> Ron Savage
>
>


More information about the cgiapp mailing list