Markus Wichitill wrote:
peter pilsl wrote:

I need to process and output data delivered via a webbrowser using the CGI-interface.
To deal with "real" unicode-data I set the whole STDIN and STDOUT to utf8 with binmode (as recommended at http://www.perldoc.com/perl5.8.0/pod/perluniintro.html. My script would not work otherwise)


While this works perfect in a standard CGI-environment it does not work under mod_perl. Perl reads the input from the CGI-form and does not read it as unicode.


STDIN is not used with mod_perl.

It depends on how you write your program. When you don't qualify your read and print calls with $r, then you do use STDIN, though mod_perl overrides it, and does the qualified $r->read() calls behind the scenes (via the perlio layer), but essentially mod_cgi and mod_perl do exactly the same thing at the end. If you turn the binmode inside your script, I think it should work just fine, since the perlio layer subclasses PerlIOBase_binmode, which is supposed to do the right thing. You can find a few examples of its usage in the modperl test suite (in the source package), just grep for 'binmode'.


I'd say, don't use CGI::param() directly, use your own param wrapper function(s) that call Encode::decode_utf8() or utf8::decode() for the returned values. Wrapper functions are useful anyway for untainting input or supporting more than one CGI input module (like Apache::Request in addition to CGI.pm).

Simplified example:

sub param
{
  my $str = undef;
  if (MODPERL) { $str = $apr->param(shift()) }
  else { $str = $cgi->param(shift()) }
  utf8::decode($str);
  return $str;
}

Boris (CC'ed) has started a similar discussion on the modperl dev list, which is now redirected to the apreq list (the home of Apache::Request), Boris is going to post the details on how to make Apache::Request handle unicode/utf8 transparently for the users. I can't see the post yet, but it should happen soon. subscribe to the [EMAIL PROTECTED] if you want to take part in that discussion.


--
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Reply via email to