Skip to content

Commit

Permalink
fixed bug in Mojolicious::Validator::Validation where every_param wou…
Browse files Browse the repository at this point in the history
…ld sometimes return an array reference containing an undef value (closes #691)
  • Loading branch information
kraih committed Oct 17, 2014
1 parent 7df037f commit 2941f5e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@

5.51 2014-10-17
- Fixed bug in Mojolicious::Validator::Validation where every_param would
sometimes return an array reference containing an undef value.
- Fixed Mojo::ByteStream and Mojo::Collection to always return true in
boolean context.

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Validator/Validation.pm
Expand Up @@ -92,7 +92,7 @@ sub required {
}

sub _param {
my $value = shift->output->{shift()};
return [] unless defined(my $value = shift->output->{shift()});
return [ref $value eq 'ARRAY' ? @$value : $value];
}

Expand Down
1 change: 1 addition & 0 deletions t/mojo/parameters.t
Expand Up @@ -67,6 +67,7 @@ is $params->to_string, 'bar=bar&foo=', 'right format';
$params = Mojo::Parameters->new(foo => 0);
is $params->param('foo'), 0, 'right value';
is_deeply $params->every_param('foo'), [0], 'right value';
is_deeply $params->every_param('bar'), [], 'no values';
is $params->to_string, 'foo=0', 'right format';
$params = Mojo::Parameters->new($params->to_string);
is $params->param('foo'), 0, 'right value';
Expand Down
1 change: 1 addition & 0 deletions t/mojolicious/dispatch.t
Expand Up @@ -72,6 +72,7 @@ is $c->param(foo => 'works')->param('foo'), 'works', 'right value';
is $c->param(foo => 'too')->param('foo'), 'too', 'right value';
is $c->param(foo => qw(just works))->param('foo'), 'works', 'right value';
is_deeply $c->every_param('foo'), [qw(just works)], 'right values';
is_deeply $c->every_param('bar'), [], 'no values';
is $c->param(foo => undef)->param('foo'), undef, 'no value';
is $c->param(foo => Mojo::Upload->new(name => 'bar'))->param('foo')->name,
'bar', 'right value';
Expand Down
2 changes: 2 additions & 0 deletions t/mojolicious/validation_lite_app.t
Expand Up @@ -36,6 +36,8 @@ my $t = Test::Mojo->new;
# Required and optional values
my $validation = $t->app->validation->input({foo => 'bar', baz => 'yada'});
is_deeply [$validation->error], [], 'no names';
is $validation->param('foo'), undef, 'no value';
is_deeply $validation->every_param('foo'), [], 'no values';
ok $validation->required('foo')->is_valid, 'valid';
is_deeply $validation->output, {foo => 'bar'}, 'right result';
is $validation->param('foo'), 'bar', 'right value';
Expand Down

0 comments on commit 2941f5e

Please sign in to comment.