For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > July 2005 > mod_perl/cgi character encoding issues









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author mod_perl/cgi character encoding issues
sy crisp

2005-07-29, 9:04 am

I have a web page with a textarea into which users can enter text
including symbols such as =E1 =E9 =A3.

When I enter the text 'a =E1 =A3 $' and submit the form under CGI I get
'a \xc3\xa1 \xc2\xa3 $' returned via cgi->param.

Running the same code under mod_perl returns 'a =C3=A1 =C2=A3 $' which
looks as though every utf8 byte has been translated into latin1.

Below is an example script to demonstrate the problem.

Can anyone tell me what I need to do to stop this double encoding of
form data under mod_perl?

Or failing that, how I can convert from 'a =C3=A1 =C2=A3 $' back to 'a
\xc3\xa1 \xc2\xa3 $'?

Thanks,

Simon

#!/usr/local/bin/perl -w

use strict;
use CGI;

binmode STDERR;

my $q =3D new CGI;
print $q->header("text/html; charset=3Dutf-8");
print "<HTML><BODY>\n";

my $msg =3D $q->param('AAAA');
print "<br>AAAA: $msg\n" if $msg;
print STDERR "AAAA: $msg\n" if $msg;

print $q->start_form(-method=3D>'GET');
print $q->textarea(-name=3D>'AAAA');
print $q->submit(-name=3D>'DOIT');
print $q->end_form();
print $q->end_html();
exit;




CGI-> AAAA: a \xc3\xa1 \xc2\xa3 $

MOD_PERL-> AAAA: a =C3=A1 =C2=A3 $

sy crisp

2005-07-29, 9:04 am

Some further information that might me useful;


Apache version 2.0.52 with AddDefaultCharset set to UTF-8

mod_perl is version 2.0.0

Perl is version 5.8.6

CGI.pm is version 3.10

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com