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

[5.2] A case with Arr:dot() #13009

Merged
merged 1 commit into from
Apr 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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