Skip Menu |

This queue is for tickets about the Data-FormValidator CPAN distribution.

Maintainer(s)' notes

This is the bug queue for Data::FormValidator.

Report information
The Basics
Id: 2361
Status: resolved
Priority: 0/
Queue: Data-FormValidator

People
Owner: MARKSTOS [...] cpan.org
Requestors: dom [...] semantico.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 2.01
Fixed in: (no value)



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)) {
[guest - Wed Apr 9 04:34:44 2003]: Show quoted text
> 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, Thanks for the report. First, I think there is a slight bug in your patch. With updating the handling of "optional_regexp", you use "my" inside the "if" statement, so that outside of the if statement, $optional_ re will always be undef. Your bug and make patch sense, but I'm having trouble reproducing it. Attached in my test case I wrote to check it. Could you review it and possibly modify it so it /fails/ when it's used with D::FV 2.01? Then when I apply the patch and the test works, I'll know the patch works, and the test will be there to make sure the bug doesn't creep back in the future. Thanks! Mark
#!/usr/bin/perl -w # This tests to make sure that when we test $@, we are testing the right thing. # inspired by a patch from Êdom@semantico.com use lib ('.','../t'); $^W = 1; print "1..1\n"; use strict; use Data::FormValidator; my $input_profile = { required => 'nothing', }; my $validator = new Data::FormValidator({default => $input_profile}); my $input_hashref = { '1_required' => 1, '1_optional' => 1, }; # populate $@ to see if D::FV dies when it shouldn't eval { die 'already dead'; }; my ($valids, $missings, $invalids, $unknowns) = ({},[],[],[]); ($valids, $missings, $invalids, $unknowns) = $validator->validate($input_hashref, 'default'); print "not " if ($@ =~ /Error compiling regular expression/); print "ok 1\n";