[BUGFIX] Do not strip sub-paths from emulated controller name 51/51451/4
authorClaus Due <claus@namelesscoder.net>
Sat, 28 Jan 2017 12:02:52 +0000 (13:02 +0100)
committerAndreas Fernandez <typo3@scripting-base.de>
Sun, 29 Jan 2017 12:09:12 +0000 (13:09 +0100)
This patch solves a special case in the integration with
Fluid. Fluid itself allows an emulated controller action
to be used, which contains a sub-path (controller name
supports this as well). However, the RenderingContext
forced use of pathinfo() on the passed path, which caused
sub-paths to be removed. The patch switches from
pathinfo() to substr() to preserve any slashes in such
controller action names.

Only direct usage of Fluid's API is affected and no
current compatibility is broken by the patch.

Change-Id: I7e1c27d55a44b957aadbace571e50afd7614d8a0
Resolves: #79519
Releases: master
Reviewed-on: https://review.typo3.org/51451
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/fluid/Classes/Core/Rendering/RenderingContext.php
typo3/sysext/fluid/Tests/Unit/Core/Rendering/RenderingContextTest.php

index 09a927e..ca68d43 100644 (file)
@@ -238,9 +238,12 @@ class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
      */
     public function setControllerAction($action)
     {
-        $action = lcfirst(pathinfo($action, PATHINFO_FILENAME));
+        $dotPosition = strpos($action, '.');
+        if ($dotPosition !== false) {
+            $action = substr($action, 0, $dotPosition);
+        }
         parent::setControllerAction($action);
-        $this->controllerContext->getRequest()->setControllerActionName($action);
+        $this->controllerContext->getRequest()->setControllerActionName(lcfirst($action));
     }
 
     /**
index 005244d..afb6326 100644 (file)
@@ -98,4 +98,38 @@ class RenderingContextTest extends \TYPO3\CMS\Components\TestingFramework\Core\U
         $this->renderingContext->_set('viewHelperVariableContainer', $viewHelperVariableContainer);
         $this->assertSame($viewHelperVariableContainer, $this->renderingContext->getViewHelperVariableContainer());
     }
+
+    /**
+     * @test
+     * @dataProvider getControllerActionTestValues
+     * @param string $input
+     * @param string $expected
+     */
+    public function setControllerActionProcessesInputCorrectly($input, $expected)
+    {
+        $subject = new RenderingContextFixture();
+        $request = $this->getMockBuilder(Request::class)->setMethods(['setControllerActionName'])->getMock();
+        $request->expects($this->at(0))->method('setControllerActionName')->with('index');
+        $request->expects($this->at(1))->method('setControllerActionName')->with(lcfirst($expected));
+        $controllerContext = $this->getMockBuilder(ControllerContext::class)->setMethods(['getRequest'])->getMock();
+        $controllerContext->expects($this->atLeastOnce())->method('getRequest')->willReturn($request);
+        $subject->setControllerContext($controllerContext);
+        $subject->setControllerAction($input);
+        $this->assertAttributeSame($expected, 'controllerAction', $subject);
+    }
+
+    /**
+     * @return array
+     */
+    public function getControllerActionTestValues()
+    {
+        return [
+            ['default', 'default'],
+            ['default.html', 'default'],
+            ['default.sub.html', 'default'],
+            ['Sub/Default', 'Sub/Default'],
+            ['Sub/Default.html', 'Sub/Default'],
+            ['Sub/Default.sub.html', 'Sub/Default']
+        ];
+    }
 }