Subject: | slightly broken regex evaluation in constraints |
perl v5.8.3, data::FormValidator 3.5.9, Windows XP Professional.
Hi Mark,
I think there is a bug in the way FormValidtor evaluates alternation | in its regex's. I've attached a snippet with two different regexs for the constraint key. You'll notice that the only difference between the two is the prescence of an alternate match pattern.
Sonny.
BTW: I'm a relative newbie to Perl and web development but I must say I quite like the functionality offered by your module.
use strict;
use CGI;
use DATA::FormValidator;
sub validate {
my $q = shift;
my $dfv_profile = {
required => [ qw( searchPredicate )],
constraints => {
searchPredicate => qr/([fl]:[a-z]{1})|([np]:[a-z]{1}\d+)/,
#Uncomment the one below to see that the constraint works when | is removed.
#searchPredicate => qr/([np]:[a-z]{1}\d+)/,
},
};
my $result = Data::FormValidator->check($q, $dfv_profile);
if ($result->has_invalid()) {
my $str = "Invalid fields: \n";
my $iHashR = $result->invalid;
my $field;
foreach $field (keys %$iHashR) {
my $valueRef = $iHashR->{$field};
foreach (@$valueRef) {
$str .= "$field=" . $_ . ";";
}
$str .= "\n";
}
print $str;
}
}
my $q = new CGI();
$q->param('searchPredicate' => 'n:d3');
validate($q);