Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: CGI::Application - Which is the proper way of handling and outputting utf8

by Juerd (Abbot)
on Nov 17, 2007 at 11:18 UTC ( #651407=note: print w/ replies, xml ) Need Help??


in reply to CGI::Application - Which is the proper way of handling and outputting utf8

CGI works with STDIN and STDOUT, so that is easy:

binmode STDIN, ":encoding(utf8)"; binmode STDOUT, ":encoding(utf8)";
However, $ENV{QUERY_STRING} might also need this treatment, but environment variables can't. This means you have to hack around it a little:
my $cgi = $ENV{REQUEST_METHOD} eq 'GET' ? CGI->new(decode_utf8 $ENV{QUERY_STRING}) : CGI->new;

(all code untested)

Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }


Comment on Re: CGI::Application - Which is the proper way of handling and outputting utf8
Select or Download Code
Re^2: CGI::Application - Which is the proper way of handling and outputting utf8
by pc88mxer (Vicar) on Nov 17, 2007 at 15:05 UTC
    I don't think this will work because QUERY_STRING is %-encoded. If C::A does not perform character decoding itself, you'll have to post-process each parameter that C::A creates with the appropirate decode (e.g. decode_utf8).

      Good catch. Indeed passing a utf8_decoded query string to CGI->new makes no sense, and you need to decode each thing individually. Time for an encoding aware CGI.pm!

Re^2: CGI::Application - Which is the proper way of handling and outputting utf8
by Anonymous Monk on Nov 18, 2007 at 13:28 UTC
    Maybe better :raw:encoding(utf8)

      Why?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://651407]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-07-11 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (236 votes), past polls