Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 ( [id://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' }

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://651407]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-03-29 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found