Subject: | Regex Validation Problem when captured value in regex == 0 |
If the constraint_method contains a capturing pair of parenthesis, and
that captured value is 0 then even if that is a valid result it will
return it as invalid in the results.
This is using:
Summary of my perl5 (revision 5 version 8 subversion 4) configuration
and
Summary of my perl5 (revision 5 version 10 subversion 0) configuration
On both Linux and Windows (Activestate)
I believe the problem can be resolved by modifying the Results.pm:
809c809
< my ($match) = ($val =~ $re);
---
Show quoted text
> my ($match) = scalar ($val =~ $re);
Though I have not tested thoroughly for side effects.
Subject: | test_DFV.pl |
#!/usr/local/bin/perl
use strict;
use Data::FormValidator;
use CGI::Simple qw(-debug2);
use Data::Dumper;
$ENV{'CONTENT_TYPE'} = '';
my $profile = {
required => [ 'TEMP' ],
constraint_methods => { 'TEMP' => qr/^(0)$/ }
};
my $CGI = new CGI::Simple( { 'TEMP' => 0 } );
# DOES NOT WORK AS EXPECTED
my $results = Data::FormValidator->check($CGI, $profile);
print "WITH qr/^(0)\$/ IT FAILS TO BE VALID\n";
print "---------- VALIDS ---------------\n";
print valids($results);
print "---------- INVALIDS ---------------\n";
print invalids($results);
my $profile3 = {
required => [ 'TEMP' ],
constraint_methods => { 'TEMP' => qr/^(9)$/ }
};
$CGI->param('TEMP' => 9);
# WORKS AS EXPECTED
$results = Data::FormValidator->check($CGI, $profile3);
print "\n\nWITH qr/^(9)\$/ IT IS VALID AND 9 IS RETURNED\n";
print "---------- VALIDS ---------------\n";
print valids($results);
print "---------- INVALIDS ---------------\n";
print invalids($results);
my $profile2 = {
required => [ 'TEMP' ],
constraint_methods => { 'TEMP' => qr/^0$/ }
};
$CGI->param('TEMP' => 0);
# WORKS AS EXPECTED
$results = Data::FormValidator->check($CGI, $profile2);
print "\n\nWITH qr/^0\$/ IT IS VALID AND 0 IS RETURNED\n";
print "-------------------------------------\n";
print "---------- VALIDS ---------------\n";
print valids($results);
print "---------- INVALIDS ---------------\n";
print invalids($results);
sub valids {
my $r = shift;
for my $f ( $r->valid() ) {
print $f, " = ", $r->valid( $f ), "\n";
}
}
sub invalids {
my $r = shift;
for my $f ( $r->invalid() ) {
print $f, " = ", $r->invalid( $f ), "\n";
}
}
__DATA__
WITH qr/^(0)$/ IT FAILS TO BE VALID
---------- VALIDS ---------------
---------- INVALIDS ---------------
TEMP = ARRAY(0x8b6c9e0)
WITH qr/^(9)$/ IT IS VALID AND 9 IS RETURNED
---------- VALIDS ---------------
TEMP = 9
---------- INVALIDS ---------------
WITH qr/^0$/ IT IS VALID AND 0 IS RETURNED
-------------------------------------
---------- VALIDS ---------------
TEMP = 0
---------- INVALIDS ---------------