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: 45177
Status: resolved
Priority: 0/
Queue: Data-FormValidator

People
Owner: MARKSTOS [...] cpan.org
Requestors: medin931 [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 4.63
Fixed in: (no value)



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 ---------------
Subject: Re: [rt.cpan.org #45177] Regex Validation Problem when captured value in regex == 0
Date: Tue, 21 Apr 2009 07:55:09 -0400
To: bug-Data-FormValidator [...] rt.cpan.org
From: Mark Stosberg <mark [...] summersault.com>
Show quoted text
> Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=45177 > > > > 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); > ---
> > my ($match) = scalar ($val =~ $re);
> > Though I have not tested thoroughly for side effects.
Thanks for the report. I'll take a look. Mark
Your welcome. I was just thinking that the problem can be avoided by changing the parenthesis to non-capturing parenthesis. That is changing: /^(0)$/ to /^(?:0)$/ Though it might become a source of a hard to find bug, in someones code. Show quoted text
> > Thanks for the report. I'll take a look. > > Mark
Subject: released, thanks
Your contribution has been released as part of Data::FormValidator 4.65 which has just been sent to be CPAN. 

Thanks for your help maintaining the module!

There are still a few open bugs that could use patched if you'd like to continue to help maintaining the module:
http://rt.cpan.org/Public/Dist/Display.html?Name=Data::FormValidator

Your help is appreciated and I always like to give credit in the "Changes" file when I can. 

     Mark