Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.
Open
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
4 changes: 2 additions & 2 deletions classes/Kohana/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ public static function path($array, $path, $default = NULL, $delimiter = NULL)
// Handle wildcards

$values = array();
foreach ($array as $arr)
foreach ($array as $wildcard_key => $arr)
{
if ($value = Arr::path($arr, implode('.', $keys)))
{
$values[] = $value;
$values[$wildcard_key] = $value;
}
}

Expand Down
16 changes: 14 additions & 2 deletions tests/kohana/ArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ public function provider_path()
3 => 'frank', // Issue #3194
),
'object' => new ArrayObject(array('iterator' => TRUE)), // Iterable object should work exactly the same
'named_users' => array( // Issue #4743
'matt' => array('name' => 'matty matt'),
'john' => array('name' => 'johnny boy', 'interests' => array('hocky' => array('length' => 2), 'football' => array())),
'frank' => 'frank',
),
);

return array(
Expand All @@ -435,14 +440,21 @@ public function provider_path()
// Test that a wildcard returns the entire array at that "level"
array($array['users'], $array, 'users.*'),
// Now we check that keys after a wilcard will be processed
array(array(0 => array(0 => 2)), $array, 'users.*.interests.*.length'),
// Fixed to check associative array indexes (issue #4743)
array(array(2 => array('hocky' => 2)), $array, 'users.*.interests.*.length'),
// See what happens when it can't dig any deeper from a wildcard
array(NULL, $array, 'users.*.fans'),
// Starting wildcards, issue #3269
array(array('matt', 'john'), $array['users'], '*.name'),
// Fixed to check associative array indexes (issue #4743)
array(array(1 => 'matt', 2 => 'john'), $array['users'], '*.name'),
// Path as array, issue #3260
array($array['users'][2]['name'], $array, array('users', 2, 'name')),
array($array['object']['iterator'], $array, 'object.iterator'),
// Wildcards with associative keys, issue #4743
array(array('matt' => 'matty matt', 'john' => 'johnny boy'), $array, 'named_users.*.name'),
array(array(2 => array('hocky' => 2)), $array, 'users.*.interests.*.length'),
array(array('matt' => 'matty matt', 'john' => 'johnny boy'), $array['named_users'], '*.name'),
array(NULL, $array, 'named_users.*.hat_color'),
);
}

Expand Down