in reply to Re: CGI hidden params vs. character encoding
in thread CGI hidden params vs. character encoding
I can only guess what might be going on under the covers when CGI sees that it is being given a new value (with the utf8 flag on) that replaces one of the existing parameters already in the "context" of the form (which does not have its utf8 flag on, even though it may already contain valid utf8 data -- it comes from an untrusted source, after all).#!/usr/bin/perl -T -w use strict; use CGI qw(:standard); use Encode; binmode STDOUT, ":utf8"; my $cgi = CGI->new(); print $cgi->header(-charset => 'UTF-8'), $cgi->start_html(-title => "Testing hidden-input character encoding", -encoding => 'UTF-8' ), $cgi->start_form; my $parms = $cgi->Vars; if ( $$parms{submit} ) { my $newtest = decode( 'utf8', $$parms{testtext} ); my $newhid = decode( 'utf8', $$parms{testtext_hid} ); delete $$parms{testtext_hid}; ### THIS IS WHAT FIXES THE PROB +LEM print "<p/> The testtext parameter as received was: ". $newtest, "<p/> The hidden parameter was: ". $newhid, $cgi->hidden( "testtext_hid", $newhid ); } else { my $testtext = "\x{444}\x{443}\x{431}\x{430}\x{440}"; print $cgi->textfield( -name => "testtext", -value => $testtext ), $cgi->hidden( "testtext_hid", $testtext ), $cgi->submit(-name => "submit", -value => "submit" ); } print $cgi->end_form, $cgi->end_html;
In any case, if I remove the existing parameter from the current "context", the assignment proceeds as expected -- no double encoding.
All in all, it smells like a bug in CGI, but I'm sufficiently far enough behind in my coding at this point, that I'm happy enough just to know that there is a way to get the intended behavior. Case closed, as far as I'm concerned.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: CGI hidden params vs. character encoding
by ikegami (Patriarch) on May 28, 2008 at 04:19 UTC | |
|
Re^3: CGI hidden params vs. character encoding
by Anonymous Monk on May 28, 2008 at 02:35 UTC |