Skip to content

Commit

Permalink
Check if exact key exists before assuming the dot notation represents…
Browse files Browse the repository at this point in the history
… segments (#14976)
  • Loading branch information
themsaid authored and taylorotwell committed Aug 23, 2016
1 parent 18b0d8e commit 39a39b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ public static function has($array, $keys)
foreach ($keys as $key) {
$subKeyArray = $array;

if (static::exists($array, $key)) {
continue;
}

foreach (explode('.', $key) as $segment) {
if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) {
$subKeyArray = $subKeyArray[$segment];
Expand Down
4 changes: 4 additions & 0 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ public function testGet()

public function testHas()
{
$array = ['products.desk' => ['price' => 100]];
$this->assertTrue(Arr::has($array, ['products.desk']));
$this->assertFalse(Arr::has($array, ['products.desk', 'missing']));

$array = ['products' => ['desk' => ['price' => 100]]];
$this->assertTrue(Arr::has($array, 'products.desk'));
$this->assertTrue(Arr::has($array, 'products.desk.price'));
Expand Down

0 comments on commit 39a39b5

Please sign in to comment.