[BUGFIX] Trim function name passed to GeneralUtility::callUserFunc() 36/50036/3
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 28 Sep 2016 06:55:50 +0000 (08:55 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Thu, 29 Sep 2016 18:33:15 +0000 (20:33 +0200)
The parameter `$funcName` could contain whitespaces, e.g. because of a
formatted FlexForm file. The parameter is now trimmed to remove the
whitespaces and to get a valid function reference.

Resolves: #78086
Releases: master, 7.6
Change-Id: I75af1da01a807102b2b1c1bced984c00be03580a
Reviewed-on: https://review.typo3.org/50036
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Eric Chavaillaz <eric@hemmer.ch>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index f4348f3..913e979 100644 (file)
@@ -3713,6 +3713,7 @@ class GeneralUtility
         if (is_object($funcName) && is_a($funcName, 'Closure')) {
             return call_user_func_array($funcName, [&$params, &$ref]);
         }
+        $funcName = trim($funcName);
         // Check persistent object and if found, call directly and exit.
         if (isset($GLOBALS['T3_VAR']['callUserFunction'][$funcName]) && is_array($GLOBALS['T3_VAR']['callUserFunction'][$funcName])) {
             return call_user_func_array([
index 5e6558b..4d3b483 100644 (file)
@@ -4587,6 +4587,16 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     /**
      * @test
      */
+    public function callUserFunctionTrimsSpaces()
+    {
+        $inputData = ['foo' => 'bar'];
+        $result = GeneralUtility::callUserFunction("\t" . self::class . '->user_calledUserFunction ', $inputData, $this);
+        $this->assertEquals('Worked fine', $result);
+    }
+
+    /**
+     * @test
+     */
     public function getAllFilesAndFoldersInPathReturnsArrayWithMd5Keys()
     {
         $directory = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('directory_');