Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Commit

Permalink
do not remove optional empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
vti committed Jul 22, 2017
1 parent ebf2d6d commit b7a1bf0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 28 deletions.
4 changes: 0 additions & 4 deletions lib/Tu/Validator.pm
Expand Up @@ -161,10 +161,6 @@ sub _gather_validated_params {
foreach my $name (keys %{$self->{fields}}) {
next if exists $result->{errors}->{$name};

next
if !$self->{fields}->{$name}->{required}
&& $self->_is_field_empty($result->{params}->{$name});

$validated_params->{$name} = $result->{params}->{$name};
}

Expand Down
24 changes: 0 additions & 24 deletions t/validator.t
Expand Up @@ -290,30 +290,6 @@ subtest 'no errors when field is optional' => sub {
ok $result->is_success;
};

subtest 'removes empty optional field' => sub {
my $validator = _build_validator();

$validator->add_optional_field('foo');
$validator->add_rule('foo', 'regexp', qr/^\d+$/);

my $result = $validator->validate({foo => ''});

is_deeply $result->all_params, {foo => ''};
is_deeply $result->validated_params, {};
};

subtest 'removes optional multiple empty values' => sub {
my $validator = _build_validator();

$validator->add_optional_field('foo', multiple => 1);
$validator->add_rule('foo', 'regexp', qr/^\d+$/);

my $result = $validator->validate({foo => ['', '']});

is_deeply $result->all_params, {foo => ['', '']};
is_deeply $result->validated_params, {};
};

subtest 'set default message' => sub {
my $validator = _build_validator();

Expand Down

0 comments on commit b7a1bf0

Please sign in to comment.