Fixes #15301: Fixed ArrayHelper::filter() to work properly with 0 in values

This commit is contained in:
hhniao
2017-12-08 21:34:29 +08:00
committed by Alexander Makarov
parent b20d2692a1
commit d2423cd6ca
3 changed files with 12 additions and 1 deletions

View File

@ -21,6 +21,7 @@ Yii Framework 2 Change Log
- Enh #15221: Added support for the `--<option> <value>` console option syntax (brandonkelly) - Enh #15221: Added support for the `--<option> <value>` console option syntax (brandonkelly)
- Enh #15221: Improved the `help/list-action-options` console command output for command options without a description (brandonkelly) - Enh #15221: Improved the `help/list-action-options` console command output for command options without a description (brandonkelly)
- Bug #15270: Resolved potential race conditions when writing generated php-files (kalessil) - Bug #15270: Resolved potential race conditions when writing generated php-files (kalessil)
- Bug #15301: Fixed `ArrayHelper::filter()` to work properly with `0` in values (hhniao)
2.0.13.1 November 14, 2017 2.0.13.1 November 14, 2017
-------------------------- --------------------------

View File

@ -938,7 +938,7 @@ class BaseArrayHelper
continue; continue;
} }
if (empty($array[$globalKey])) { if (!key_exists($globalKey, $array)) {
continue; continue;
} }
if ($localKey === null) { if ($localKey === null) {

View File

@ -1269,5 +1269,15 @@ class ArrayHelperTest extends TestCase
$this->assertEquals(ArrayHelper::filter($array, ['X']), []); $this->assertEquals(ArrayHelper::filter($array, ['X']), []);
$this->assertEquals(ArrayHelper::filter($array, ['X.Y']), []); $this->assertEquals(ArrayHelper::filter($array, ['X.Y']), []);
$this->assertEquals(ArrayHelper::filter($array, ['A.X']), []); $this->assertEquals(ArrayHelper::filter($array, ['A.X']), []);
$tmp = [
'a' => 0,
'b' => '',
'c' => false,
'd' => null,
'e' => true,
];
$this->assertEquals(ArrayHelper::filter($tmp, array_keys($tmp)), $tmp);
} }
} }