Skip to content

Commit

Permalink
Merge pull request #317 from ocean90/fix/array-filter-data
Browse files Browse the repository at this point in the history
Unset references to prevent data corruption
  • Loading branch information
filisko authored Dec 13, 2020
2 parents 3c94b7c + 18c6e37 commit e8416a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gump.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,8 @@ public function filter(array $input, array $filterset)
foreach ($input_array as &$value) {
$value = $this->call_filter($parsed_rule['rule'], $value, $parsed_rule['param']);
}

unset($input_array, $value);
}
}

Expand Down
18 changes: 17 additions & 1 deletion tests/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ public function testItForwardsParametersToNativePHPFunctions()
$this->assertTrue(password_verify('my_password', $result['field']));
}

public function testArrayDataIsNotOverridden()
{
$result = $this->gump->filter([
'field_one' => ['100a', '200'],
'field_two' => 'yes',
], [
'field_one' => 'sanitize_numbers',
'field_two' => 'boolean',
]);

$this->assertEquals([
'field_one' => ['100', '200'],
'field_two' => true,
], $result);
}

// public function testNestedArrays()
// {
// $data = [
Expand Down Expand Up @@ -169,4 +185,4 @@ public function testItForwardsParametersToNativePHPFunctions()
// ]
// ], $result);
// }
}
}

0 comments on commit e8416a3

Please sign in to comment.