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!

In reply to Re^2: Escaping %params by DaisyLou
in thread Escaping %params by DaisyLou

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.