mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 13:02:24 +08:00
Fix #18395: Fix regression in yii\helpers\BaseArrayHelper::filter() (allowing filtering arrays with numeric keys)
This commit is contained in:
@ -17,6 +17,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #16492: Fix eager loading Active Record relations when relation key is a subject to a type-casting behavior (bizley)
|
||||
- Bug #18435: Fix ensuring Active Record relation links' keys to be strings (bizley)
|
||||
- Bug #18435: Change the check order whether an object is an implementation of `Arrayable` or `JsonSerializable` in `\yii\base\ArrayableTrait::toArray()` and `\yii\rest\Serializer::serialize()` (spell6inder)
|
||||
- Bug #18395: Fix regression in `yii\helpers\BaseArrayHelper::filter()` (allowing filtering arrays with numeric keys) (bizley)
|
||||
|
||||
|
||||
2.0.39.3 November 23, 2020
|
||||
|
||||
@ -944,13 +944,17 @@ class BaseArrayHelper
|
||||
$excludeFilters = [];
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
if ($filter[0] === '!') {
|
||||
if (!is_string($filter) && !is_int($filter)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_string($filter) && strpos($filter, '!') === 0) {
|
||||
$excludeFilters[] = substr($filter, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
$nodeValue = $array; //set $array as root node
|
||||
$keys = explode('.', $filter);
|
||||
$keys = explode('.', (string) $filter);
|
||||
foreach ($keys as $key) {
|
||||
if (!array_key_exists($key, $nodeValue)) {
|
||||
continue 2; //Jump to next filter
|
||||
@ -971,7 +975,7 @@ class BaseArrayHelper
|
||||
|
||||
foreach ($excludeFilters as $filter) {
|
||||
$excludeNode = &$result;
|
||||
$keys = explode('.', $filter);
|
||||
$keys = explode('.', (string) $filter);
|
||||
$numNestedKeys = count($keys) - 1;
|
||||
foreach ($keys as $i => $key) {
|
||||
if (!array_key_exists($key, $excludeNode)) {
|
||||
|
||||
Reference in New Issue
Block a user