Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

9.50 UNRELEASED
- Fixed Mojolicious::Validator::Validation to croak with a clear message naming the filter when an unknown
filter name is passed to "optional" or "required", instead of crashing with a confusing
"Can't locate object method """ error.

9.49 2026-08-10
- Added EXPERIMENTAL support for partitioned cookies. (rawleyfowler)
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojolicious/Validator/Validation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ sub optional {
return $self->topic($name) unless defined(my $input = $self->input->{$name});

my @input = ref $input eq 'ARRAY' ? @$input : ($input);
for my $cb (map { $self->validator->filters->{$_} } @filters) {
for my $filter (@filters) {
my $cb = $self->validator->filters->{$filter};
Carp::croak qq{Unknown filter "$filter"} unless defined $cb;
@input = map { $self->$cb($name, $_) } @input;
}
$self->output->{$name} = @input > 1 ? \@input : $input[0] if @input && !grep { !defined } @input;
Expand Down
6 changes: 6 additions & 0 deletions t/mojolicious/validation_lite_app.t
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ subtest 'Custom filter' => sub {
is_deeply $v->output, {foo => ['foo="bar"', 'foo="baz"']}, 'right result';
};

subtest 'Unknown filter' => sub {
my $v = $t->app->validation->input({foo => 'bar'});
eval { $v->optional('foo', 'does_not_exist') };
like $@, qr/Unknown filter "does_not_exist"/, 'clear error naming the unknown filter';
};

subtest 'Multiple empty values' => sub {
my $v = $t->app->validation;
ok !$v->has_data, 'no data';
Expand Down
Loading