
substituting an exact negated string: can I?
Hello,
I want to get rid of anything between < and > from form data unless it is a
hyperlink.
Taking from this form parser (asterisks showing the line I want to modify):
sub Parse_Form {
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
$ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $buffer,
$ENV{'CONTENT_LENGTH'});
if ($ENV{'QUERY_STRING'}) {
}
} else {
print "Content-type: text/html\n\n";
print "<P>Use Post or Get";
}
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ 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 ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
Quote:
}
1;
I want to change the line: $value =~ s/<!--(.|\n)*-->//g; (shown by
asterisks) to something like the following:
$value =~ s/<[^a href]*?>//gi;
The only problem is that the substitution is looking for any one of the
letters: a, space, h, r, e, and f. It won't allow me to substitute a
negated string of this form. Is there a way to negate 'a href' without the
brackets? How else might I go about this? The goal is to remove any HTML
and SSI except for hyperlinks that a person may enter into a form. I know I
can see if I can match something I don't want in the form data and tell the
user not to do that but I would rather have the script remove it.
Thanks for any help you can offer.
-Mike Morgan