Subject: | value of any_errors gets added to msgs even when there are no errors |
In my Data::FormValidator validation profile, I've added a custom 'any_errors' message
msgs => {
'any_errors' => 'some_errors'
},
The docs suggest that the 'some_errors' key will be present in the result's msgs only if there were errors returned. However, it seems to me that it is always added, even if the input data passed the validation profile.
I've attached a test script with failing tests for this case.
Environment: Data::FormValidator 4.02 on perl 5.8.5 (Centos 4.1)
Michael
#!/usr/bin/perl
use strict;
use Test::More 'no_plan';
use Data::FormValidator;
my $dfv_standard_any_errors = Data::FormValidator->new({});
my $dfv_custom_any_errors = Data::FormValidator->new({},{msgs => { any_errors => 'some_errors' }});
my %profile = (
required => 'foo',
);
my %good_input = (
'foo' => 1,
);
my %bad_input = (
'bar' => 1,
);
my ($results, $msgs);
# standard 'any_errors', good input
$results = $dfv_standard_any_errors->check(\%good_input, \%profile);
$msgs = $results->msgs;
ok($results, "[standard any_errors] good input passed");
ok(!keys %$msgs, "[standard any_errors] no error messages");
# standard 'any_errors', bad input
$results = $dfv_standard_any_errors->check(\%bad_input, \%profile);
$msgs = $results->msgs;
ok(!$results, "[standard any_errors] bad input caught");
ok(keys %$msgs, "[standard any_errors] error messages reported");
# custom 'any_errors', good input
$results = $dfv_custom_any_errors->check(\%good_input, \%profile);
$msgs = $results->msgs;
ok($results, "[standard any_errors] good input passed");
ok(!keys %$msgs, "[standard any_errors] no error messages");
ok(!$msgs->{'some_errors'}, "[standard any_errors] 'some_errors' not reported");
# custom 'any_errors', bad input
$results = $dfv_custom_any_errors->check(\%bad_input, \%profile);
$msgs = $results->msgs;
ok(!$results, "[standard any_errors] bad input caught");
ok(keys %$msgs, "[standard any_errors] error messages reported");
ok($msgs->{'some_errors'}, "[standard any_errors] 'some_errors' reported");