[BUGFIX] Fix access to empty ObjectStorage with numeric key 33/34433/2
authorMathias Brodala <mbrodala@pagemachine.de>
Thu, 30 Oct 2014 10:40:42 +0000 (11:40 +0100)
committerMarkus Klein <klein.t3@reelworx.at>
Fri, 21 Nov 2014 09:53:37 +0000 (10:53 +0100)
This prevents a warning error triggered by spl_object_hash being called
with an integer/string and can be caused by Fluid like this:

{object.relations.0}

Resolves: #62553
Releases: master, 6.2
Change-Id: Ie7d2a249e17f719142482781c2a96d093ff5f94c
Reviewed-on: http://review.typo3.org/34433
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/extbase/Classes/Persistence/ObjectStorage.php
typo3/sysext/extbase/Tests/Unit/Persistence/ObjectStorageTest.php

index 830d821..5de3cc2 100644 (file)
@@ -157,7 +157,7 @@ class ObjectStorage implements \Countable, \Iterator, \ArrayAccess, ObjectMonito
         * @return boolean
         */
        public function offsetExists($object) {
-               return isset($this->storage[spl_object_hash($object)]);
+               return is_object($object) && isset($this->storage[spl_object_hash($object)]);
        }
 
        /**
index 90390c4..8019ba6 100644 (file)
@@ -105,6 +105,22 @@ class ObjectStorageTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         */
+       public function offsetExistsWorksWithEmptyStorageAndIntegerKey() {
+               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $this->assertEquals($objectStorage->offsetExists(0), FALSE);
+       }
+
+       /**
+        * @test
+        */
+       public function offsetExistsWorksWithEmptyStorageAndStringKey() {
+               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $this->assertEquals($objectStorage->offsetExists('0'), FALSE);
+       }
+
+       /**
+        * @test
+        */
        public function getInfoReturnsTheDataAssociatedWithTheCurrentIteratorEntry() {
                $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
                $object1 = new \StdClass();