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

People
Owner: MARKSTOS [...] cpan.org
Requestors: sonnychee [...] yahoo.com
Cc:
AdminCc:

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



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);
From: Sonny
Incidentally, I got around the issue by pushing my regex into a subroutine reference. So no rush to fix this. [guest - Wed Jul 28 00:45:04 2004]: Show quoted text
> 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
| Show quoted text
> 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.
Date: Wed, 28 Jul 2004 10:45:23 -0500
From: Mark Stosberg <mark [...] summersault.com>
To: Guest via RT <bug-Data-FormValidator [...] rt.cpan.org>
CC: sonnychee [...] yahoo.com
Subject: Re: [cpan #7145] slightly broken regex evaluation in constraints
RT-Send-Cc:
On Wed, Jul 28, 2004 at 12:45:05AM -0400, Guest via RT wrote: Show quoted text
> > This message about Data-FormValidator was sent to you by guest <> via rt.cpan.org > > Full context and any attached attachments can be found at: > <URL: https://rt.cpan.org/Ticket/Display.html?id=7145 > > > 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.
Thanks for the report Sonny. Would you willing to take your report a step further, and also provide some tests that indicate that your Regexp works as you expect by itself? Your test script might look like this: ##### use Test::More qw/no_plan/; my $re = qr/at/; my @to_pass = (qw/cat hat bat/); my @to_fail = (qw/flu zoo boo/); for (@to_pass) { like($_, $re, "string '$_' should pass RE"); } for (@to_fail) { unlike($_, $re, "string '$_' should fail RE"); } ############## You could then extend the test script to test a number of REs with DFV to narrow down the problem. (My initial hunch is that this not a DFV problem, because I don't think we handle REs with "|" in them specially.) Let me know how it goes.