Skip to content

Commit

Permalink
Merge pull request #6 from kielabokkie/hotfix/array-issue
Browse files Browse the repository at this point in the history
Fix incorrect concealing of first key of array
  • Loading branch information
kielabokkie authored May 23, 2020
2 parents 611d8ce + 5ee9670 commit bc7e29b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Concealer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function conceal($input, array $keys = [])
private function handleCollection($input)
{
$output = $input->map(function ($item, $key) {
if (in_array($key, $this->keys) === true) {
if (in_array($key, $this->keys, true) === true) {
return $input[$key] = '********';
}

Expand All @@ -75,7 +75,7 @@ private function handleCollection($input)
private function handleArray($input)
{
foreach ($input as $key => $item) {
if (in_array($key, $this->keys) === true) {
if (in_array($key, $this->keys, true) === true) {
$input[$key] = '********';
continue;
}
Expand Down
14 changes: 13 additions & 1 deletion tests/ConcealerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,25 @@ public function it_handles_numeric_keys_for_collections(): void
'password' => new Collection([
'test',
'secret',
])
]),
'test' => new Collection([
'test',
'secret',
]),
'test2' => [
'test',
'secret',
]
]);

$output = $this->concealer->conceal($data);

$this->assertEquals('wouter', $output['username']);
$this->assertEquals('********', $output['password']);
$this->assertEquals('test', $output['test'][0]);
$this->assertEquals('secret', $output['test'][1]);
$this->assertEquals('test', $output['test2'][0]);
$this->assertEquals('secret', $output['test2'][1]);
}

/** @test */
Expand Down

0 comments on commit bc7e29b

Please sign in to comment.