Bug #89510
closedJsonView does not handle _only/_exclude correctly
100%
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
Updated by Gerrit Code Review about 5 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62111
Updated by Markus Klein about 5 years ago
- Description updated (diff)
- Category deleted (
Extbase) - Assignee deleted (
Markus Klein) - Target version deleted (
next-patchlevel)
Updated by Markus Klein about 5 years ago
- Category set to Extbase
- Assignee set to Markus Klein
Updated by Gerrit Code Review about 5 years ago
Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62071
Updated by Gerrit Code Review about 5 years ago
Patch set 1 for branch TYPO3_8-7 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62130
Updated by Markus Klein about 5 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 3f4058edf9a2877b7c974ed08c61bb06ab277bca.
Updated by Gerrit Code Review about 5 years ago
- Status changed from Resolved to Under Review
Patch set 2 for branch TYPO3_8-7 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62130
Updated by Markus Klein about 5 years ago
- Status changed from Under Review to Resolved
Applied in changeset fdc3e54215021996856038879bab6243ed5a7c8a.
Updated by Gerrit Code Review about 5 years ago
- Status changed from Resolved to Under Review
Patch set 3 for branch TYPO3_8-7 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62130
Updated by Markus Klein about 5 years ago
- Status changed from Under Review to Resolved
Applied in changeset f47a8e718993e0b93b2b601a3d0a4d93744078ca.
Updated by Benni Mack almost 5 years ago
- Status changed from Resolved to Closed