[BUGFIX] Invalid argument supplied for foreach in ExtensionModelUtility 71/28671/4
authorPhilipp Gampe <philipp.gampe@typo3.org>
Sun, 23 Mar 2014 15:47:19 +0000 (16:47 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Mon, 24 Mar 2014 12:40:40 +0000 (13:40 +0100)
Dependecies might be given as empty string, e.g.
array (
'depends' =>
array (
'typo3' => '4.5.0-6.2.99',
),
'conflicts' => '',
'suggests' =>
array (
),
),

This is how the kickstarter used to generate it.

Resolves: #57207
Releases: 6.2
Change-Id: I314249f8883ee82fdfa9ee81aca7a526716ccade
Reviewed-on: https://review.typo3.org/28671
Reviewed-by: Alexander Opitz
Tested-by: Alexander Opitz
Reviewed-by: Ernesto Baschny
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/extensionmanager/Classes/Utility/ExtensionModelUtility.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/ExtensionModelUtilityTest.php

index 4e02834..341a195 100644 (file)
@@ -69,6 +69,10 @@ class ExtensionModelUtility {
                $unserializedDependencies = unserialize($dependencies);
                $dependenciesObject = new \SplObjectStorage();
                foreach ($unserializedDependencies as $dependencyType => $dependencyValues) {
+                       // Dependencies might be given as empty string, e.g. conflicts => ''
+                       if (!is_array($dependencyValues)) {
+                               continue;
+                       }
                        foreach ($dependencyValues as $dependency => $versions) {
                                if ($dependencyType && $dependency) {
                                        $versionNumbers = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionsStringToVersionNumbers($versions);
index 7ec16c0..98a1a50 100644 (file)
@@ -146,4 +146,18 @@ class ExtensionModelUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $dependencyModelMock->expects($this->atLeastOnce())->method('setHighestVersion')->with($this->identicalTo($returnValue[1]));
                $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
        }
+
+       /**
+        * @test
+        */
+       public function convertDependenciesToObjectCanDealWithEmptyStringDependencyValues() {
+               $dependencies = array(
+                       'depends' => ''
+               );
+               $serializedDependencies = serialize($dependencies);
+               /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
+               $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
+               $dependencyObject = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
+               $this->assertSame(0, $dependencyObject->count());
+       }
 }