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');