diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Widget/Controller/PaginateController.php b/typo3/sysext/fluid/Classes/ViewHelpers/Widget/Controller/PaginateController.php index 7c5f47247350d1d9e1dced18d2ae60286c448725..55603593018344ee1c83fe7065b0bdb34da98b97 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Widget/Controller/PaginateController.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Widget/Controller/PaginateController.php @@ -182,9 +182,10 @@ class PaginateController extends AbstractWidgetController return $modifiedObjects; } elseif ($this->objects instanceof ObjectStorage) { $modifiedObjects = []; - $endOfRange = $offset + $itemsPerPage; + $objectArray = $this->objects->toArray(); + $endOfRange = min($offset + $itemsPerPage, count($objectArray)); for ($i = $offset; $i < $endOfRange; $i++) { - $modifiedObjects[] = $this->objects->toArray()[$i]; + $modifiedObjects[] = $objectArray[$i]; } return $modifiedObjects; } elseif (is_array($this->objects)) { diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Widget/Controller/PaginateControllerTest.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Widget/Controller/PaginateControllerTest.php index af2b26ddda656b5bd8fdf2dca36ab0ac39452fb4..48b041595454eac11565f392f60b16a912d1b9e3 100644 --- a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Widget/Controller/PaginateControllerTest.php +++ b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Widget/Controller/PaginateControllerTest.php @@ -220,6 +220,25 @@ class PaginateControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC $this->assertSame($expectedPortion, $this->controller->_call('prepareObjectsSlice', 10, 10)); } + /** + * @test + */ + public function prepareObjectsSliceReturnsCorrectPortionForObjectStorageAndLastPage() + { + $this->controller->_set('currentPage', 3); + $objects = new ObjectStorage(); + for ($i = 0; $i <= 25; $i++) { + $item = new \stdClass; + $objects->attach($item); + } + $this->controller->_set('objects', $objects); + $expectedPortion = []; + for ($j = 20; $j <= 25; $j++) { + $expectedPortion[] = $objects->toArray()[$j]; + } + $this->assertSame($expectedPortion, $this->controller->_call('prepareObjectsSlice', 10, 20)); + } + /** * @test */