Project

General

Profile

Actions

Bug #89510

closed

JsonView does not handle _only/_exclude correctly

Added by Markus Klein over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Must have
Assignee:
Category:
Extbase
Target version:
-
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 #1

Updated by Gerrit Code Review over 4 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

Actions #2

Updated by Markus Klein over 4 years ago

  • Description updated (diff)
  • Category deleted (Extbase)
  • Assignee deleted (Markus Klein)
  • Target version deleted (next-patchlevel)
Actions #3

Updated by Markus Klein over 4 years ago

  • Category set to Extbase
  • Assignee set to Markus Klein
Actions #4

Updated by Gerrit Code Review over 4 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

Actions #5

Updated by Gerrit Code Review over 4 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

Actions #6

Updated by Markus Klein over 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #7

Updated by Gerrit Code Review over 4 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

Actions #8

Updated by Markus Klein over 4 years ago

  • Status changed from Under Review to Resolved
Actions #9

Updated by Gerrit Code Review over 4 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

Actions #10

Updated by Markus Klein over 4 years ago

  • Status changed from Under Review to Resolved
Actions #11

Updated by Benni Mack over 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF