From d8aabd9697e240df69c2cca26c05308db4b06020 Mon Sep 17 00:00:00 2001 From: lorenzolosa <11164571+lorenzolosa@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:59:09 +0200 Subject: [PATCH] apply excludeUnvalidatedArrayKeys to list validation (#52658) --- src/Illuminate/Validation/Validator.php | 2 +- tests/Validation/ValidationValidatorTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 2dff098c11a2..8a0b2871f903 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -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; diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index a1c49716febf..36935b84d417 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -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()