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

[8.x] Fix unvalidated array keys without implicit attributes #38052

Merged
merged 1 commit into from
Jul 19, 2021

Conversation

bonroyage
Copy link
Contributor

This PR aims to fix an issue that occurs when, in combination with the excludeUnvalidatedArrayKeys option on the validator, the array under validation does not have any implicit attributes. For example user.name instead of users.*.name.

This is fixed by also checking the keys present in getRules() instead of just the $implicitAttributes. As a result, the regex had to be altered slightly to check for the presence of at least one . following the attribute key. Otherwise it would not return anything when using just array without nested rules.

Validator::make([
    'admin' => ['name' => 'Mohamed', 'location' => 'cairo'], 
    'users' => [['name' => 'Mohamed', 'location' => 'cairo']]
], [
    'admin' => 'array',
    'admin.name' => 'string',
    'users' => 'array',
    'users.*.name' => 'string'
]);

image

@taylorotwell taylorotwell merged commit 9ee9c11 into laravel:8.x Jul 19, 2021
@bonroyage bonroyage deleted the fix-unvalidated-array-keys branch July 19, 2021 13:18
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

Successfully merging this pull request may close these issues.

2 participants