Skip to content

Commit

Permalink
Hash::filter() should not exclude 0.0
Browse files Browse the repository at this point in the history
Refs #10385
  • Loading branch information
markstory committed Mar 10, 2017
1 parent 8d0e1fa commit e698891
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions lib/Cake/Test/Case/Utility/HashTest.php
Expand Up @@ -655,8 +655,21 @@ public function testContains() {
* @return void * @return void
*/ */
public function testFilter() { public function testFilter() {
$result = Hash::filter(array('0', false, true, 0, array('one thing', 'I can tell you', 'is you got to be', false))); $result = Hash::filter(array(
$expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be')); '0',
false,
true,
0,
0.0,
array('one thing', 'I can tell you', 'is you got to be', false)
));
$expected = array(
'0',
2 => true,
3 => 0,
4 => 0.0,
5 => array('one thing', 'I can tell you', 'is you got to be')
);
$this->assertSame($expected, $result); $this->assertSame($expected, $result);


$result = Hash::filter(array(1, array(false))); $result = Hash::filter(array(1, array(false)));
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Hash.php
Expand Up @@ -573,7 +573,7 @@ public static function filter(array $data, $callback = array('self', '_filter'))
* @return bool * @return bool
*/ */
protected static function _filter($var) { protected static function _filter($var) {
if ($var === 0 || $var === '0' || !empty($var)) { if ($var === 0 || $var === 0.0 || $var === '0' || !empty($var)) {
return true; return true;
} }
return false; return false;
Expand Down

0 comments on commit e698891

Please sign in to comment.