Bug #89510
Updated by Markus Klein about 5 years ago
h2. Setup <pre> if ($this->view instanceof \TYPO3\CMS\Extbase\Mvc\View\JsonView) JsonView) { $this->view->setConfiguration( [ 'value' => $configuration = [ 'items' 'verifier' => [ '_descend' => [ 'recentRequests' => [ '_descendAll' => [ '_exclude' => ['foo'], ], ], ], ], ], ] ); $value ]; $this->view->setVariablesToRender(array_keys($configuration)); $this->view->setConfiguration($configuration); $verifier = [ 'items' 'recentRequests' => [ ['name' => 'a'], 'a', 'foo' => 1], ['name' => 'b'], 'b', 'foo' => 1], ] ]; } $this->view->assign('value', $value); $this->view->assign('verifier', $verifier); </pre> h2. Expected JSON output <pre> {"recentRequests": [{"name": "a"},{"name": "b"}]} </pre> h2. Actual JSON output <pre> {"recentRequests": {"1": {"name": "b"}]} </pre> h2. 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.) h2. Fix Adjust the in_array call. Simply enforce the data type