[BUGFIX] Trim function name passed to GeneralUtility::callUserFunc() 68/50068/2
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:39 +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/50068
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 f617389..69e0cf7 100644 (file)
@@ -4324,6 +4324,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 31f6f4d..02b0154 100644 (file)
@@ -4707,6 +4707,16 @@ text with a ' . $urlMatch . '$|s'],
     /**
      * @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/' . $this->getUniqueId('directory_');