Actions
Bug #89510
closedJsonView does not handle _only/_exclude correctly
Start date:
2019-10-25
Due date:
% Done:
100%
Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:
Description
Setup¶
if ($this->view instanceof \TYPO3\CMS\Extbase\Mvc\View\JsonView) { $this->view->setConfiguration( [ 'value' => [ 'items' => [ '_exclude' => ['foo'], ], ], ] ); $value = [ 'items' => [ ['name' => 'a'], ['name' => 'b'], ] ]; } $this->view->assign('value', $value);
Expected JSON output¶
{"recentRequests": [{"name": "a"},{"name": "b"}]}
Actual JSON output¶
{"recentRequests": {"1": {"name": "b"}]}
Reasoning¶
\TYPO3\CMS\Extbase\Mvc\View\JsonView::transformValue
checks for _exclude
keys and does so by using in_array
.
Unfortunately it does not set the third parameter to true, which would enforce the data type.
This way, when processing the array of "recentRequests", each array key is checked against the _exclude
array.
For the first element in the array (key = 0) this yields true, hence the first array element is skipped (excluded).
(in_array(0, ['foo']) === true
!!)
Ultimately, this leads to an PHP array with missing first index 0, which causes the data to be converted to a JSON object (instead of array).
(The program on the client side expects an array though and crashes.)
Fix¶
Adjust the in_array call.
Simply enforce the data type
Actions