Skip to content

Commit

Permalink
apply excludeUnvalidatedArrayKeys to list validation (#52658)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzolosa authored Sep 5, 2024
1 parent 839c2d0 commit d8aabd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public function validated()
$value = data_get($this->getData(), $key, $missingValue);

if ($this->excludeUnvalidatedArrayKeys &&
in_array('array', $rules) &&
(in_array('array', $rules) || in_array('list', $rules)) &&
$value !== null &&
! empty(preg_grep('/^'.preg_quote($key, '/').'\.+/', array_keys($this->getRules())))) {
continue;
Expand Down
9 changes: 9 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8933,6 +8933,15 @@ public function testExcludingArrays()
$validator->excludeUnvalidatedArrayKeys = true;
$this->assertTrue($validator->passes());
$this->assertSame(['users' => [1, 2, 3]], $validator->validated());

$validator = new Validator(
$this->getIlluminateArrayTranslator(),
['users' => [['name' => 'Mohamed', 'location' => 'cairo']]],
['users' => 'list', 'users.*.name' => 'string']
);
$validator->excludeUnvalidatedArrayKeys = true;
$this->assertTrue($validator->passes());
$this->assertSame(['users' => [['name' => 'Mohamed']]], $validator->validated());
}

public function testExcludeUnless()
Expand Down

0 comments on commit d8aabd9

Please sign in to comment.