Subject: | missing_optional_valid implies missing_optional_invalid_valid |
Date: | Thu, 16 Aug 2007 11:44:39 -0400 |
To: | <bug-Data-FormValidator [...] rt.cpan.org> |
From: | "Robert Juliano" <rjuliano [...] 2co.com> |
Summary: invalid optional fields end up both valid and invalid when
missing_optional_valid is set to true.
Broken in: 4.51
Expect invalid fields not to be valid.
Test and patch included.
----------------------------------------------------------------------------
---
### TEST
use strict;
use Test::More tests => 2;
use Data::FormValidator;
my $data = {
optional_invalid => 'invalid'
};
my $profile = {
optional => [qw/optional_invalid/],
constraints => {
optional_invalid => qr/^valid$/
},
missing_optional_valid => 1
};
my $results = Data::FormValidator->check($data, $profile);
my $valid = $results->valid();
my $invalid = $results->invalid();
ok( exists $invalid->{'optional_invalid'}, 'optional_invalid is invalid');
ok( !exists $valid->{'optional_invalid'}, 'optional_invalid is not
valid');
#---------------------------------------------------------------------------
----
### PATCH
--- Data/FormValidator/Results.pm.orig 2007-08-15 16:06:50.000000000 -0400
+++ Data/FormValidator/Results.pm 2007-08-15 16:18:11.000000000 -0400
@@ -364,11 +364,6 @@
my $force_method_p = 1;
$self->_check_constraints($private_constraint_methods,\%valid,$untaint_all,\
%untaint_hash, $force_method_p);
- # all invalid fields are removed from valid hash
- foreach my $field (keys %{ $self->{invalid} }) {
- delete $valid{$field};
- }
-
# add back in missing optional fields from the data hash if we need to
foreach my $field ( keys %data ) {
if ($profile->{missing_optional_valid} and $optional{$field}
and (not exists $valid{$field})) {
@@ -376,6 +371,11 @@
}
}
+ # all invalid fields are removed from valid hash
+ foreach my $field (keys %{ $self->{invalid} }) {
+ delete $valid{$field};
+ }
+
my ($missing,$invalid);
$self->{valid} ||= {};