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

Conditional Validation with "sometimes" fails on empty array #13007

Closed
JeanLucEsser opened this issue Apr 4, 2016 · 6 comments
Closed

Conditional Validation with "sometimes" fails on empty array #13007

JeanLucEsser opened this issue Apr 4, 2016 · 6 comments

Comments

@JeanLucEsser
Copy link

The title is self-explanatory.

Applying the following rule on an empty array [] passes validation:
sometimes|required

It should fail as the same rule correctly fails for a null value or an empty string.

@themsaid
Copy link
Member

themsaid commented Apr 4, 2016

Can you share the attribute name?

'users.*.username' => 'sometimes|required'

@JeanLucEsser
Copy link
Author

I didn't mean on an array of values, but on an empty array as a value.

Say you test the following attribute: task => []

The rule 'task' => 'required' correctly fails.
The rule 'task' => 'sometimes|required' passes but should fail.

@themsaid
Copy link
Member

themsaid commented Apr 4, 2016

This test currently passes:

$trans = $this->getRealTranslator();
$v = new Validator($trans, ['name' => []], ['name' => 'sometimes|required']);
$this->assertFalse($v->passes());

@JeanLucEsser
Copy link
Author

Fair enough. The plot thickens.

This test currently fails:

$trans = $this->getRealTranslator();
$v = new Validator($trans, ['foo' => ['bar' => []]], ['foo.bar' => 'sometimes|required']);
$this->assertFalse($v->passes());

Looks like the issue arises only with nested arrays of values.

@themsaid
Copy link
Member

themsaid commented Apr 4, 2016

It's fixed, will be working as expected as of the next patch release.

@JeanLucEsser
Copy link
Author

Great, thanx, closing the issue then.
Best.

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