Skip to content

Commit

Permalink
fixes #434: case-insensitivity on scrub_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
David Huebner committed Jan 23, 2019
1 parent 8997d1e commit d448404
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/Scrubber.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function scrub(&$data, $replacement = '********', $path = '')
return $data;
}

$fields = array_flip($fields);
// Scrub fields is case insensitive, so force all fields to lowercase
$fields = array_change_key_case(array_flip($fields), CASE_LOWER);

return $this->internalScrub($data, $fields, $replacement, $path);
}
Expand Down Expand Up @@ -110,7 +111,7 @@ protected function scrubArray(&$arr, $fields, $replacement = '********', $path =
return;
}

if (isset($fields[$key])) {
if (isset($fields[strtolower($key)])) {
$val = $replacement;
} else {
$val = $scrubber->internalScrub($val, $fields, $replacement, $current);
Expand Down
23 changes: 17 additions & 6 deletions tests/ScrubberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ private function scrubRecursiveStringRecursiveDataProvider()
'sensitive' => 'scrubit',
'arg2' => array(
'arg3' => 'val 3',
'sensitive' => 'scrubit'
'sensitive' => 'scrubit',
'SENSITIVE' => 'scrubit',
'sensitive2' => 'scrubit'
)
)
),
Expand All @@ -280,7 +282,8 @@ private function scrubRecursiveStringRecursiveDataProvider()
array( // $scrubFields
'sensitive data',
'recursive sensitive data',
'sensitive'
'sensitive',
'SENSITIVE2'
),
array( // $expected
'non sensitive data 1' => '123',
Expand All @@ -295,7 +298,9 @@ private function scrubRecursiveStringRecursiveDataProvider()
'sensitive' => 'xxxxxxxx',
'arg2' => array(
'arg3' => 'val 3',
'sensitive' => 'xxxxxxxx'
'sensitive' => 'xxxxxxxx',
'SENSITIVE' => 'xxxxxxxx',
'sensitive2' => 'xxxxxxxx'
)
)
),
Expand Down Expand Up @@ -325,14 +330,20 @@ public function scrubArrayDataProvider()
'flat data array' => array(
array( // $testData
'non sensitive data' => '123',
'sensitive data' => '456'
'sensitive data' => '456',
'UPPERCASE SENSITIVE DATA' => '789',
'also sensitive data' => '012'
),
array( // $scrubFields
'sensitive data'
'sensitive data',
'uppercase sensitive data',
'ALSO SENSITIVE DATA'
),
array( // $expected
'non sensitive data' => '123',
'sensitive data' => '********'
'sensitive data' => '********',
'UPPERCASE SENSITIVE DATA' => '********',
'also sensitive data' => '********'
)
),
'recursive data array' => array(
Expand Down

0 comments on commit d448404

Please sign in to comment.