From bf55c094fb7a3ddbc87b48df078d2285a4cd77b6 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Mon, 4 Apr 2016 13:21:46 +0000 Subject: [PATCH] fix on array dot --- src/Illuminate/Support/Arr.php | 2 +- tests/Support/SupportArrTest.php | 9 +++++++++ tests/Validation/ValidationValidatorTest.php | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Arr.php b/src/Illuminate/Support/Arr.php index 456b867f026c..940978d62bb1 100755 --- a/src/Illuminate/Support/Arr.php +++ b/src/Illuminate/Support/Arr.php @@ -105,7 +105,7 @@ public static function dot($array, $prepend = '') $results = []; foreach ($array as $key => $value) { - if (is_array($value)) { + if (is_array($value) && ! empty($value)) { $results = array_merge($results, static::dot($value, $prepend.$key.'.')); } else { $results[$prepend.$key] = $value; diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index 3b37d761f534..fb5bea8dc7ad 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -41,6 +41,15 @@ public function testDot() { $array = Arr::dot(['foo' => ['bar' => 'baz']]); $this->assertEquals(['foo.bar' => 'baz'], $array); + + $array = Arr::dot([]); + $this->assertEquals([], $array); + + $array = Arr::dot(['foo' => []]); + $this->assertEquals(['foo' => []], $array); + + $array = Arr::dot(['foo' => ['bar' => []]]); + $this->assertEquals(['foo.bar' => []], $array); } public function testExcept() diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 5630764b15e2..4a62f1c3c81c 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -2099,6 +2099,15 @@ public function testValidateImplicitEachWithAsterisks() $this->assertFalse($v->passes()); } + public function testSometimesFailOnEmptyArrayInImplicitRules() + { + $trans = $this->getRealTranslator(); + + $data = ['names' => [['second' => []]]]; + $v = new Validator($trans, $data, ['names.*.second' => 'sometimes|required']); + $this->assertFalse($v->passes()); + } + public function testValidateImplicitEachWithAsterisksForRequiredNonExistingKey() { $trans = $this->getRealTranslator();