Skip to content

Commit

Permalink
Merge pull request #8425 from grimpirate/grimpirate-patch-1
Browse files Browse the repository at this point in the history
fix: [Validation] DotArrayFilter returns incorrect array when numeric index array is passed
  • Loading branch information
kenjis authored Jan 18, 2024
2 parents 1e61ebd + 75d5400 commit 0788018
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Validation/DotArrayFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function run(array $indexes, array $array): array
$segments
);

$result = array_merge_recursive($result, self::filter($segments, $array));
$result = array_replace_recursive($result, self::filter($segments, $array));
}

return $result;
Expand Down
15 changes: 15 additions & 0 deletions tests/system/Validation/DotArrayFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,19 @@ public function testRunNestedArray()
];
$this->assertSame($expected, $result);
}

public function testRunReturnOrderedIndices()
{
$data = [
'foo' => [
2 => 'bar',
0 => 'baz',
1 => 'biz',
],
];

$result = DotArrayFilter::run(['foo.2', 'foo.0', 'foo.1'], $data);

$this->assertSame($data, $result);
}
}

0 comments on commit 0788018

Please sign in to comment.