Skip to content

Commit

Permalink
TransformsRequest.php cleanArray function fix. (#36002)
Browse files Browse the repository at this point in the history
When I send a request which has nested json body fields this function does recursive operation and it throws 'maximum function nested level of 256 reached.'.
Size of my data is less than 256.
If I use foreach loop it does not make recursive operation.

My request:
{"sample1":"sample","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[{"title":"aa","children":[]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}],"sample2":[{"sample3":"sample","name":"sample"}]}
  • Loading branch information
ozgurkadarozgur authored Jan 22, 2021
1 parent 49b0d52 commit cc03df3
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ protected function cleanParameterBag(ParameterBag $bag)
*/
protected function cleanArray(array $data, $keyPrefix = '')
{
return collect($data)->map(function ($value, $key) use ($keyPrefix) {
return $this->cleanValue($keyPrefix.$key, $value);
})->all();
foreach ($data as $key => $value) {
$data[$key] = $this->cleanValue($keyPrefix.$key, $value);
}

return collect($data)->all();
}

/**
Expand Down

1 comment on commit cc03df3

@andrey-helldar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.... Maybe it's better like this? Not?

protected function cleanArray(array $data, $keyPrefix = '')
{
    return array_map(function($value) use ($keyPrefix) {
        $this->cleanValue($keyPrefix.$key, $value);
    }, $data);
}

or

protected function cleanArray(array $data, $keyPrefix = '')
{
    foreach ($data as $key => &$value) {
        $value => $this->cleanValue($keyPrefix.$key, $value);
    }

    return $data;
}

?

Please sign in to comment.