Skip to content

Commit

Permalink
Fixes yiisoft#14423: Fixed ArrayHelper::merge behavior with null va…
Browse files Browse the repository at this point in the history
…lues for integer-keyed elements
  • Loading branch information
dmirogin authored and samdark committed Jul 13, 2017
1 parent fe607b8 commit 6e223e6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Yii Framework 2 Change Log
- Enh #14417: Added configuration for headers in PHP files generated by `message/extract` command (rob006)
- Enh #13835: Added `yii\web\Request::getOrigin()` method that returns HTTP_ORIGIN of current CORS request (yyxx9988)
- Bug #14165: Set `_slave` of `Connection` to `false` instead of `null` in `close` method (rossoneri)

- Bug #14423: Fixed `ArrayHelper::merge` behavior with null values for integer-keyed elements (dmirogin)

2.0.12 June 05, 2017
--------------------
Expand Down
2 changes: 1 addition & 1 deletion framework/helpers/BaseArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static function merge($a, $b)
} elseif ($v instanceof ReplaceArrayValue) {
$res[$k] = $v->value;
} elseif (is_int($k)) {
if (isset($res[$k])) {
if (array_key_exists($k, $res)) {
$res[] = $v;
} else {
$res[$k] = $v;
Expand Down
22 changes: 22 additions & 0 deletions tests/framework/helpers/ArrayHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,28 @@ public function testMergeWithReplace()
$this->assertEquals($expected, $result);
}

public function testMergeWithNullValues()
{
$a = [
'firstValue',
null,
];
$b = [
'secondValue',
'thirdValue'
];

$result = ArrayHelper::merge($a, $b);
$expected = [
'firstValue',
null,
'secondValue',
'thirdValue',
];

$this->assertEquals($expected, $result);
}

/**
* @see https://github.com/yiisoft/yii2/pull/11549
*/
Expand Down

0 comments on commit 6e223e6

Please sign in to comment.