[BUGFIX] Cleaner scripts crashes due to incomplete flexform content 22/36722/3
authorJose Antonio Guerra <jaguerra@icti.es>
Fri, 6 Feb 2015 18:32:29 +0000 (19:32 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 6 Feb 2015 19:54:45 +0000 (20:54 +0100)
Failure to check arguments used on recursive function call
causes PHP runtime error.

Resolves: #64914
Releases: master, 6.2
Change-Id: Id61ae9961415ab5d9d4294b224c90f2e02df6f14
Reviewed-on: http://review.typo3.org/36722
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Configuration/FlexForm/FlexFormTools.php
typo3/sysext/core/Tests/Unit/Configuration/FlexForm/FlexFormToolsTest.php [new file with mode: 0644]

index 398fc5c..76276f0 100644 (file)
@@ -211,16 +211,18 @@ class FlexFormTools {
                                                                }
                                                        }
                                                } else {
-                                                       // Array traversal:
-                                                       $this->traverseFlexFormXMLData_recurse($value['el'], $editData[$key]['el'], $PA, $path . '/' . $key . '/el');
+                                                       // Array traversal
+                                                       if (is_array($editData) && is_array($editData[$key])) {
+                                                               $this->traverseFlexFormXMLData_recurse($value['el'], $editData[$key]['el'], $PA, $path . '/' . $key . '/el');
+                                                       }
                                                }
                                        } elseif (is_array($value['TCEforms']['config'])) {
                                                // Processing a field value:
                                                foreach ($PA['vKeys'] as $vKey) {
                                                        $vKey = 'v' . $vKey;
-                                                       // Call back:
-                                                       if ($PA['callBackMethod_value']) {
-                                                               $this->callBackObj->{$PA['callBackMethod_value']}($value, $editData[$key][$vKey], $PA, $path . '/' . $key . '/' . $vKey, $this);
+                                                       // Call back
+                                                       if ($PA['callBackMethod_value'] && is_array($editData) && is_array($editData[$key])) {
+                                                               $this->executeCallBackMethod($PA['callBackMethod_value'], array($value, $editData[$key][$vKey], $PA, $path . '/' . $key . '/' . $vKey, $this));
                                                        }
                                                }
                                        }
@@ -230,6 +232,17 @@ class FlexFormTools {
        }
 
        /**
+        * Execute method on callback object
+        *
+        * @param string $methodName Method name to call
+        * @param array $parameterArray Parameters
+        * @return mixed Result of callback object
+        */
+       protected function executeCallBackMethod($methodName, array $parameterArray) {
+               return call_user_func_array(array($this->callBackObj, $methodName), $parameterArray);
+       }
+
+       /**
         * Returns an array of available languages to use for FlexForm operations
         *
         * @return array
diff --git a/typo3/sysext/core/Tests/Unit/Configuration/FlexForm/FlexFormToolsTest.php b/typo3/sysext/core/Tests/Unit/Configuration/FlexForm/FlexFormToolsTest.php
new file mode 100644 (file)
index 0000000..a5bbbc8
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Configuration\FlexForm;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Tests\UnitTestCase;
+use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
+
+/**
+ * Test case
+ */
+class FlexFormToolsTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @test
+        */
+       public function traverseFlexFormXmlDataRecurseDoesNotFailOnNotExistingField() {
+               $dataStruct = array(
+                       'dummy_field' => array(
+                               'TCEforms' => array(
+                                       'config' => array(),
+                               ),
+                       ),
+               );
+               $pA = array(
+                       'vKeys' => array('ES'),
+                       'callBackMethod_value' => 'dummy',
+               );
+               $editData = '';
+               /** @var \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools|\PHPUnit_Framework_MockObject_MockObject $subject */
+               $subject = $this->getMock('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools', array('executeCallBackMethod'));
+               $subject->expects($this->never())->method('executeCallBackMethod');
+               $subject->traverseFlexFormXMLData_recurse($dataStruct, $editData, $pA);
+       }
+
+       /**
+        * @test
+        */
+       public function traverseFlexFormXmlDataRecurseDoesNotFailOnNotExistingArrayField() {
+               $dataStruct = array(
+                       'dummy_field' => array(
+                               'type' => 'array',
+                               'el' => 'field_not_in_data',
+                       ),
+               );
+               $pA = array(
+                       'vKeys' => array('ES'),
+                       'callBackMethod_value' => 'dummy',
+               );
+               $editData = array(
+                       'field' => array(
+                               'el' => 'dummy',
+                       ),
+               );
+               $editData2 = '';
+               /** @var \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools|\PHPUnit_Framework_MockObject_MockObject $subject */
+               $subject = $this->getMock('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools');
+               $this->assertEquals(
+                       $subject->traverseFlexFormXMLData_recurse($dataStruct, $editData, $pA),
+                       $subject->traverseFlexFormXMLData_recurse($dataStruct, $editData2, $pA)
+               );
+       }
+
+}