Skip to content

Commit

Permalink
[bugfix] ArrDots::search could not handle searches ending in a wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
pdscopes committed Aug 30, 2017
1 parent 7cf0f0c commit 9f423f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ArrDots.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ public static function search($array, $key, $wildcard = null)
// If this segment is a wildcard
if ($segment === $wildcard) {
$values = [];
$subKey = implode('.', $segments);
foreach (array_keys($array) as $attr) {
foreach (static::search($array, $attr.'.'.$subKey, $wildcard) as $attrKey => $value) {
$subKey = implode('.', array_merge([$attr], $segments));
foreach (static::search($array, $subKey, $wildcard) as $attrKey => $value) {
$values[$pattern . $attrKey] = $value;
}
}
Expand Down
8 changes: 7 additions & 1 deletion tests/Unit/ArrDotsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testSearch()
'array3' => [
['sub-array1' => [['item1' => 'item2-value'], ['item1' => 'item3-value']]],
['sub-array1' => [['item1' => 'item4-value']]],
]
],
];

$this->assertEquals([
Expand All @@ -112,6 +112,12 @@ public function testSearch()
$this->assertEquals([
'array0' => [1, 2, 3, 4]
], ArrDots::search($data, 'array0'));
$this->assertEquals([
'array0.0' => 1,
'array0.1' => 2,
'array0.2' => 3,
'array0.3' => 4,
], ArrDots::search($data, 'array0.*', '*'));
$this->assertEquals([
'array2.0.sub-array0' => [1, 2, 3, 4],
'array2.1.sub-array0' => [1, 2, 3, 4],
Expand Down

0 comments on commit 9f423f0

Please sign in to comment.