Skip to content

Commit

Permalink
Merge pull request #13009 from themsaid/array-dot-dilemma
Browse files Browse the repository at this point in the history
[5.2] A case with Arr:dot()
  • Loading branch information
taylorotwell committed Apr 4, 2016
2 parents 341fe49 + bf55c09 commit 4461e6f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4461e6f

Please sign in to comment.