Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation rules DSL syntax is not checked (at least in 'like' rules) which may lead to allowing invalid data. #11

Open
allter opened this issue May 18, 2018 · 1 comment

Comments

@allter
Copy link

allter commented May 18, 2018

Validation rules DSL syntax is not checked (at least in 'like' rules).

This may lead to silently passing through invalid data when programmer makes a mistake.

In the following example rules 'like' and 'max_length' are not properly separated which is difficult to spot. The result is that the check is enforced only some of the time (depending on the perl hash walking order which is different each run).

use Test::More;
use Validator::LIVR qw();

my $validator = Validator::LIVR->new({
  # wrong line:
  field => ['required', {like => "^[A-Za-z]+\$", max_length => 20}],
  # correct line:
  # field => ['required', {like => "^[A-Za-z]+\$"}, {max_length => 20}],
});
my $passed_fields = $validator->validate( { field => "invalid_data" } );
ok ! $passed_fields, 'invalid data is not allowed';
done_testing;
@koorchik
Copy link
Owner

Good point! I will add more tests to the main LIVR test suite covering this issue. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants