Gossamer Forum
Home : General : Perl Programming :

another encoding problem

Quote Reply
another encoding problem
i have a file that contains this excerpt:
Code:
# Select fields. Field name => 'comma seperated list of drop down options'.
%select_fields = (
);


# client is both radio and checkbox so checkbox can be used on search form


# Radio fields. Field name => comma seperated list of radio buttons.
%radio_fields = (
'Type' => 'DBMan,Delicia,Client,D2015',
'Display' => 'Yes,No,Deleted',
'Followup' => 'Yes,No',
'Client' => 'delicia,dreydev,ohs1968,bhccwga,interiorsolutions,danaespa,knue,langford,kudzu,suwaneeday',
'Status_public' => 'n/a,Planning,Coding,Alpha,Beta,Complete',
'Status_private' => 'n/a,Planning,Coding,Alpha,Beta,Complete'
);


# Checkbox fields. Field name => Checkbox value.
%checkbox_fields = (
'Category' => 'Configuration,Variable,Flag,Subroutine,Field,FieldType,Problem,TroubleTip,File,Hack,ChangeLog,Other',
'Client' => 'delicia,dreydev,ohs1968,bhccwga,knue',
'Installed' => 'delicia,dreydev,ohs1968,bhccwga,knue'
);



i have a routine to read the file into a textarea. when i save the file, all the % signs are changed to weird characters. how do i prevent this? thanks!
Quote Reply
Re: [delicia] another encoding problem In reply to
i have tracked down the cause but i have no idea how to correct it. here's the code that parses the form input:
Code:
sub parse_form {
# --------------------------------------------------------
my (%in);
my ($buffer, $pair, $name, $value);
PAIR: foreach $name ($query->param()) {
@value = $query->param("$name");
$value = join '~~', @value;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
if ($value eq "---") { next PAIR; }
if ($value eq "http://") { next PAIR; } # Removes default beginning of URLs
unless ($value) { next PAIR; }
$in{$name} = $value;
}
return %in;
}

when the above code was inserted another thing that was added before the call to parse form was
Code:
use CGI;
$query = new CGI;
Quote Reply
Re: [delicia] another encoding problem In reply to
It's hard to know without seeing more of the code / example input / output etc. I would suggest adding debugging in, and print that debugging out so you can spot where the issue comes in. DBMan is a pretty antiquated script by now, which would really be better working with DBManSQL (still old, but much more flexible :))

In later GT scripts, you would simply grab the values like:

Code:
my $in = $IN->get_hash;

Much easier and cleaner :)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] another encoding problem In reply to
i commented the lines:
Code:
$value =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
that seems to have fixed the problem without breaking anything else. someone at stackoverflow said i was double decoding with those lines, whatever that means!
Quote Reply
Re: [delicia] another encoding problem In reply to
Yup its possible. Double encoding basically means you do it once, and then do it again You get this a lot with UTF-8 where it converts and charges into \123\123, and then you encode again and it converts to \234\567\234\567, which then obviously buggers up whats being saved/ shown :)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] another encoding problem In reply to
that makes sense, but i don't know where it was decoded the first time! which lines did that?
Quote Reply
Re: [delicia] another encoding problem In reply to
It depends on what this is from:

Code:
PAIR: foreach $name ($query->param()) {

Is $query as CGi.pm object, or a DBMan function? If its a CGI.pm object, then its already decoded by that :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!