[BUGFIX] EmConfUtility accesses non-arrays 57/23857/5
authorMarkus Klein <klein.t3@mfc-linz.at>
Mon, 16 Sep 2013 19:20:12 +0000 (21:20 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Thu, 26 Sep 2013 22:27:58 +0000 (00:27 +0200)
Properly check for array-type before accessing
or counting the variable.

Resolves: #52045
Releases: 6.2, 6.1, 6.0, 4.7, 4.5
Change-Id: Id161fddadbbcadd462de36e8227278107f2e7a3a
Reviewed-on: https://review.typo3.org/23857
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/extensionmanager/Classes/Utility/EmConfUtility.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/EmConfUtilityTest.php

index 6e19894..fdbbf5c 100644 (file)
@@ -132,17 +132,14 @@ $EM_CONF[$_EXTKEY] = ' . $emConf . ';
         * @return string A simple dependency list for display
         */
        static public function dependencyToString($dependency, $type = 'depends') {
-               if (is_array($dependency)) {
-                       if (isset($dependency[$type]['php'])) {
-                               unset($dependency[$type]['php']);
-                       }
-                       if (isset($dependency[$type]['typo3'])) {
-                               unset($dependency[$type]['typo3']);
-                       }
-                       $dependencyString = count($dependency[$type]) ? implode(',', array_keys($dependency[$type])) : '';
-                       return $dependencyString;
+               if (!is_array($dependency) || !is_array($dependency[$type])) {
+                       return '';
                }
-               return '';
+
+               unset($dependency[$type]['php']);
+               unset($dependency[$type]['typo3']);
+
+               return implode(',', array_keys($dependency[$type]));
        }
 
        /**
index 4b0d9dc..0f370b3 100644 (file)
@@ -88,5 +88,36 @@ class EmConfUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $fixture = new \TYPO3\CMS\Extensionmanager\Utility\EmConfUtility();
                $this->assertEquals($expected, $fixture->fixEmConf($input));
        }
+
+       /**
+        * @test
+        */
+       public function dependencyToStringUnsetsDependencies() {
+               $config = array(
+                       'depends' => array(
+                               'php' => '5.0',
+                               'something' => 'foo',
+                               'anything' => 'bar'
+                       )
+               );
+               $expected = 'something,anything';
+
+               /** @var \TYPO3\CMS\Extensionmanager\Utility\EmConfUtility $fixture */
+               $fixture = $fixture = new \TYPO3\CMS\Extensionmanager\Utility\EmConfUtility();
+               $result = $fixture::dependencyToString($config);
+               $this->assertEquals($expected, $result);
+       }
+
+       /**
+        * @test
+        */
+       public function dependencyToStringDealsWithInvalidInput() {
+               $input = array(
+                       'depends' => 'hello world'
+               );
+               /** @var \TYPO3\CMS\Extensionmanager\Utility\EmConfUtility $fixture */
+               $fixture = $fixture = new \TYPO3\CMS\Extensionmanager\Utility\EmConfUtility();
+               $this->assertEquals('', $fixture::dependencyToString($input));
+       }
 }
 ?>
\ No newline at end of file