Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Escaping %params

by DaisyLou (Sexton)
on Jan 21, 2014 at 15:16 UTC ( [id://1071480]=note: print w/replies, xml ) Need Help??


in reply to Re: Escaping %params
in thread Escaping %params

I've distilled all this advice this as best I can.
============ something.lib ============ sub safer { my $hash = shift; my %safer; while (my ($k, $v) = each %$hash) { s/\\//g for $k, $v; s/0x00//g for $k, $v; s/0x08//g for $k, $v; s/0x09//g for $k, $v; s/0x0a/\n/g for $k, $v; s/0x0d/\r/g for $k, $v; s/"/\\"/g for $k, $v; s/%/\\%/g for $k, $v; s/'/\\'/g for $k, $v; s/_/\_/g for $k, $v; $safer{$k} = $v; } return %safer; } ================ something.cgi... ================ use warnings; use strict; use CGI; use CGI::Carp; print "Content-type: text/html\n\n"; # marker my $cgi = CGI->new(); $cgi->param; my %params; for my $name ($cgi->param) { my @values = $cgi->param($name); $params{$name} = @values > 1 ? \@values : $values[0]; } %params=safer(\%params); # marker for my $param (keys %params) { print "$param: $params{$param}<br>" }
The stuff between the two markers will replace the existing
sub main { my $cgi = CGI->new(); my %params = $cgi->Vars();
... in the existing scripts. This is running under mod-perl (w/ regcooker). Are there any "gotchas" I should be aware of here? Thanks to all you monks for all your help!

Replies are listed 'Best First'.
Re^3: Escaping %params
by Anonymous Monk on Jan 21, 2014 at 21:38 UTC

    A problem is with CGI->Vars , you never want to use CGI->Vars, CGI->Vars is for perl4, Vars mangles (encodes, serializes, packs, implodes) the data, its backwards compatibility for some 1993 stuff

    You want "escapeHTML" from CGI.pm

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1071480]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-23 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found