waspcatcher has asked for the wisdom of the Perl Monks concerning the following question:
I am parsing input from a CGI form, and so want to run everything through regular expressions to untaint the data.
Yesterday, I grabbed the data ($data = $form->param('input') )and sent it through a reg exp ( $data =~ /(^[\w-.\s\(\)\']+)$/ ) and whenever metacharacters were part of $data, it would knock Perl over.
Then I used $data = "\Q$data\E" before putting it through the regexp, which worked fine.
Today I carry on working, and suddenly the regexp was complaining about everything. I took a look at what was happening, and it was effectively being escaped twice. Perl wasn't complaining (I'm using strict, warnings, CGI qw(:standard) and CGI::Carp qw/fatalsToBrowser/.
It's working now, but I don't know what would make illegal characters knock it over yesterday and not today.
Any info would be greatly appreciated.Edit Masem 2001-11-08 - CODE tag on regex.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: metacharacters and reg exps
by waspcatcher (Initiate) on Nov 09, 2001 at 18:39 UTC |