Subject: | The utf8 bit is not set when CGI.pm reads the query string or STDIN |
Hi,
The utf8 bit is not set when CGI.pm reads the query string or STDIN (which
is UTF-8 encoded) and set the params, the effect of this is that the
query parameter gets double encoded (e.g. when concatenated with an utf8
string with the bit set).
Find attached example.
Thanks for Your help,
Michael Nilsson
--
#!/usr/bin/perl -w
use strict;
use 5.008_000;
use CGI ();
## set the layer of STDOUT to UTF-8
binmode(STDOUT, ':utf8');
## enable UTF-8 in source code
use utf8;
my $query = CGI->new();
$query->charset('UTF-8');
print $query->header(),
$query->start_html(),
'Färger',
$query->start_form(-method => 'POST',
-action => $query->url()),
$query->textarea(-name => 'text',
-default => 'starting value Färger'),
$query->submit(),
$query->endform(),
$query->end_html();
--
Adding this code after creating the CGI instance fixes the problem
--
use Encode ();
foreach my $param ($query->param()) {
foreach my $i (0 .. $#{$query->{$param}}) {
## Messing with Perl's Internals,
## this is probably not the right way to do this
Encode::_utf8_on($query->{$param}->[$i]);
}
}