Skip to content
Snippets Groups Projects
Commit a2c1edc0 authored by Oliver Klee's avatar Oliver Klee Committed by Stefan Bürk
Browse files

[BUGFIX] Fix crashes for current and getInfo on empty storages

For empty storages, we need to avoid accessing inexistent array elements.

Resolves: #97417
Relates: #97554
Releases: main, 11.5
Change-Id: Ieee36b4c0ede9726ce936030f631a3322e3813a9
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74765


Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
parent 7a637e81
Branches
Tags
No related merge requests found
......@@ -180,7 +180,7 @@ class LazyObjectStorage extends ObjectStorage implements LoadingStrategyInterfac
}
/**
* @return TEntity The object at the current iterator position.
* @return TEntity|null The object at the current iterator position.
*
* @see \TYPO3\CMS\Extbase\Persistence\ObjectStorage::current
*/
......
......@@ -123,13 +123,14 @@ class ObjectStorage implements \Countable, \Iterator, \ArrayAccess, ObjectMonito
/**
* Returns the current storage entry.
*
* @return TEntity The object at the current iterator position.
* @return TEntity|null The object at the current iterator position.
*/
#[\ReturnTypeWillChange]
public function current()
{
$item = current($this->storage);
return $item['obj'];
return $item['obj'] ?? null;
}
/**
......@@ -265,7 +266,8 @@ class ObjectStorage implements \Countable, \Iterator, \ArrayAccess, ObjectMonito
public function getInfo()
{
$item = current($this->storage);
return $item['inf'];
return $item['inf'] ?? null;
}
/**
......
......@@ -25,6 +25,30 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
*/
class ObjectStorageTest extends UnitTestCase
{
/**
* @test
*/
public function currentForAnEmptyStorageReturnsNull(): void
{
$objectStorage = new ObjectStorage();
$result = $objectStorage->current();
self::assertNull($result);
}
/**
* @test
*/
public function getInfoForAnEmptyStorageReturnsNull(): void
{
$objectStorage = new ObjectStorage();
$result = $objectStorage->getInfo();
self::assertNull($result);
}
/**
* @test
*/
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment