Subject: | required_regexp check slightly broken |
I've just noticed a problem with Data::FormValidator in the required_regexp check. Because of the way that it's written, if there is no required_regexp in the profile *and* something exists in $@ (from a previous eval in my code as it happens), then the check will fail.
The attached patch corrects this, and the same problem in optional_regexp. I haven't looked further to see if there are any other situations in the code which may require the same treatment.
-Dom
--- FormValidator.pm.orig 2003-04-09 08:55:23.000000000 +0100
+++ FormValidator.pm 2003-04-09 08:57:13.000000000 +0100
@@ -721,11 +721,17 @@
my %optional = map { $_ => 1 } _arrayify($profile->{optional});
# loop through and add fields to %required and %optional based on regular expressions
- my $required_re = eval 'sub { $_[0] =~ '. $profile->{required_regexp} . '}' if $profile->{required_regexp};
- die "Error compiling regular expression $required_re: $@" if $@;
+ my $required_re;
+ if ($profile->{required_regexp}) {
+ $required_re = eval 'sub { $_[0] =~ '. $profile->{required_regexp} . '}';
+ die "Error compiling regular expression $required_re: $@" if $@;
+ }
- my $optional_re = eval 'sub { $_[0] =~ '. $profile->{optional_regexp} . '}' if $profile->{optional_regexp};
- die "Error compiling regular expression $optional_re: $@" if $@;
+ my $optional_re;
+ if ($profile->{optional_regexp}) {
+ my $optional_re = eval 'sub { $_[0] =~ '. $profile->{optional_regexp} . '}';
+ die "Error compiling regular expression $optional_re: $@" if $@;
+ }
foreach my $k (keys %valid) {
if ($required_re && $required_re->($k)) {