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

People
Owner: MARKSTOS [...] cpan.org
Requestors: william [...] knowmad.com
Cc:
AdminCc:

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



Subject: Inconsistency with required_regexp & missing/empty fields
Hi Mark, I've come across an inconsistency in the behavior of DFV when using required_regexp. If I have a regexp that contains character classes, I will not get a warning about missing fields. However, if the regexp does not contain char classes, I do get an entry in the missing array. I've attached a revised version of the test 26 which demonstrates this behavior. My preference would be that the required_regexp was displayed as missing whether it had char classes or not. Thanks, William
# Testing new support for 'qr'. -mls use Test::More qw/no_plan/; use Data::FormValidator; my %FORM = ( stick => 'big', speak => 'softly', bad_email => 'doops', good_email => 'great@domain.com', 'short_name' => 'tim', 'not_oops' => 'hoops', 'untainted_with_qr' => 'Slimy', ); my $results = Data::FormValidator->check(\%FORM, { required_regexp => qr/stick/, optional_regexp => '/_email$/', constraint_regexp_map => { qr/email/ => 'email', }, field_filter_regexp_map => { qr/_name$/ => 'ucfirst', }, required => 'speak', optional => [qw/short_name not_oops untainted_with_qr/], constraints => { not_oops => { name => 'start_with_oop', constraint => qr/^oop/, }, untainted_with_qr => qr/(Slim)/, speak => qr/quietly|softly/, stick => qr/big|large/, }, msgs => { constraints => { 'start_with_oop' => 'testing named qr constraints', } }, untaint_constraint_fields => [qw/untainted_with_qr/], }); ok ($results->valid('stick') eq 'big','using qr for regexp quoting'); ok ($results->valid('speak'),'using alternation with qr works'); ok ($results->valid('good_email'), 'expected to pass constraint'); ok ($results->invalid('bad_email'), 'expected to fail constraint'); is($results->valid('short_name'),'Tim', 'field_filter_regexp_map'); my $msgs = $results->msgs; like($msgs->{not_oops},qr/testing named/, 'named qr constraints'); is($results->valid('untainted_with_qr'),'Slim', 'untainting with qr'); # Test empty required_regexp with a regular regexp %FORM = ( stick => '', speak => 'softly', bad_email => 'doops', good_email => 'great@domain.com', 'short_name' => 'tim', 'not_oops' => 'hoops', 'untainted_with_qr' => 'Slimy', ); $results = Data::FormValidator->check(\%FORM, { required_regexp => qr/stick/, optional_regexp => '/_email$/', constraint_regexp_map => { qr/email/ => 'email', }, field_filter_regexp_map => { qr/_name$/ => 'ucfirst', }, required => 'speak', optional => [qw/short_name not_oops untainted_with_qr/], constraints => { not_oops => { name => 'start_with_oop', constraint => qr/^oop/, }, untainted_with_qr => qr/(Slim)/, speak => qr/quietly|softly/, stick => qr/big|large/, }, msgs => { constraints => { 'start_with_oop' => 'testing named qr constraints', } }, untaint_constraint_fields => [qw/untainted_with_qr/], }); #use Data::Dumper; #warn Dumper($results); ok (scalar @{$results->missing()},'Check for empty required_regexp field that DOES NOT contains character class'); # Test empty required_regexp %FORM = ( stick => '', speak => 'softly', bad_email => 'doops', good_email => 'great@domain.com', 'short_name' => 'tim', 'not_oops' => 'hoops', 'untainted_with_qr' => 'Slimy', ); $results = Data::FormValidator->check(\%FORM, { required_regexp => qr/\w+stick/, optional_regexp => '/_email$/', constraint_regexp_map => { qr/email/ => 'email', }, field_filter_regexp_map => { qr/_name$/ => 'ucfirst', }, required => 'speak', optional => [qw/short_name not_oops untainted_with_qr/], constraints => { not_oops => { name => 'start_with_oop', constraint => qr/^oop/, }, untainted_with_qr => qr/(Slim)/, speak => qr/quietly|softly/, stick => qr/big|large/, }, msgs => { constraints => { 'start_with_oop' => 'testing named qr constraints', } }, untaint_constraint_fields => [qw/untainted_with_qr/], }); #use Data::Dumper; #warn Dumper($results); ok (scalar @{$results->missing()},'Check for empty required_regexp field that contains character class'); # Test missing required_regexp %FORM = ( speak => 'softly', bad_email => 'doops', good_email => 'great@domain.com', 'short_name' => 'tim', 'not_oops' => 'hoops', 'untainted_with_qr' => 'Slimy', ); $results = Data::FormValidator->check(\%FORM, { required_regexp => qr/\w+stick/, optional_regexp => '/_email$/', constraint_regexp_map => { qr/email/ => 'email', }, field_filter_regexp_map => { qr/_name$/ => 'ucfirst', }, required => 'speak', optional => [qw/short_name not_oops untainted_with_qr/], constraints => { not_oops => { name => 'start_with_oop', constraint => qr/^oop/, }, untainted_with_qr => qr/(Slim)/, speak => qr/quietly|softly/, stick => qr/big|large/, }, msgs => { constraints => { 'start_with_oop' => 'testing named qr constraints', } }, untaint_constraint_fields => [qw/untainted_with_qr/], }); #use Data::Dumper; #warn Dumper($results); ok (scalar @{$results->missing()},'Check for missing required_regexp field that contains character class');
Date: Wed, 27 Jul 2005 16:55:02 -0500
From: Mark Stosberg <mark [...] summersault.com>
To: Guest via RT <bug-Data-FormValidator [...] rt.cpan.org>
Subject: Re: [cpan #13895] Inconsistency with required_regexp & missing/empty fields
RT-Send-Cc:
On Wed, Jul 27, 2005 at 05:38:12PM -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=13895 > > > Hi Mark, > > I've come across an inconsistency in the behavior of DFV when using > required_regexp. If I have a regexp that contains character classes, I > will not get a warning about missing fields. However, if the regexp > does not contain char classes, I do get an entry in the missing array. > I've attached a revised version of the test 26 which demonstrates this > behavior. My preference would be that the required_regexp was > displayed as missing whether it had char classes or not.
William, I believe there is confusion present. I think if you take your test can reduce it to the simplest possible variation that contains the bug, you will find that no field names matched the regular expression: \w+stick Because there are no fields that match that, they can't be missing. They are unknown. If you continue to feel there is a bug, please submit reduced test cases, with and without character classes. I'm skeptical there is a bug here, because with the qr// syntax, we can treat the thing directly as a regular expression and no special handling of character classes should be happening. Namaste, Mark
[mark@summersault.com - Wed Jul 27 17:55:05 2005]: Show quoted text
> I believe there is confusion present.
Yes indeed there was. Thanks for helping me to understand the nature of that profile specification. I have attached a patch against the FormValidator.pm file to help clarify this point. What I was hoping for was a way to say that the query must have fields which match this regexp. That's quite different than what required_regexp does. Is there an option that will do that for me? Thanks, William
Date: Thu, 28 Jul 2005 14:09:21 -0500
From: Mark Stosberg <mark [...] summersault.com>
To: Guest via RT <bug-Data-FormValidator [...] rt.cpan.org>
Subject: Re: [cpan #13895] Inconsistency with required_regexp & missing/empty fields
RT-Send-Cc:
William -- On Wed, Jul 27, 2005 at 11:20:59PM -0400, Guest via RT wrote: Show quoted text
> > Yes indeed there was. Thanks for helping me to understand the nature of > that profile specification. I have attached a patch against the > FormValidator.pm file to help clarify this point.
I didn't find a patch attached. But you inspired me to create my own to clarify the issue. Here's what I did: --- old-dfv/lib/Data/FormValidator.pm 2005-07-17 21:44:21.000000000 -0500 +++ new-dfv/lib/Data/FormValidator.pm 2005-07-28 14:05:50.000000000 -0500 @@ -354,8 +354,8 @@ required_regexp => qr/city|state|zipcode/, -This is a regular expression used to specify additional fields which are -required. +This is a regular expression used to specify additional field names for which values +will be required. =head2 require_some Show quoted text
> What I was hoping for was a way to say that the query must have fields > which match this regexp. That's quite different than what > required_regexp does. Is there an option that will do that for me?
When you say 'fields', do you mean 'field values', as opposed to the 'field names' that are currently matched? If you are interacting with values and not names, then you need a constraint, and it sounds like a customized one at that. I'm still not sure I understand exactly what you are after. Mark