Commit cbb4e482 authored by Claus Due's avatar Claus Due Committed by Andreas Fernandez
Browse files

[BUGFIX] Do not strip sub-paths from emulated controller name

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: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Philipp Gampe's avatarPhilipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe's avatarPhilipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
parent a7e2c7e7
...@@ -238,9 +238,12 @@ class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext ...@@ -238,9 +238,12 @@ class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
*/ */
public function setControllerAction($action) public function setControllerAction($action)
{ {
$action = lcfirst(pathinfo($action, PATHINFO_FILENAME)); $dotPosition = strpos($action, '.');
if ($dotPosition !== false) {
$action = substr($action, 0, $dotPosition);
}
parent::setControllerAction($action); parent::setControllerAction($action);
$this->controllerContext->getRequest()->setControllerActionName($action); $this->controllerContext->getRequest()->setControllerActionName(lcfirst($action));
} }
/** /**
......
...@@ -98,4 +98,38 @@ class RenderingContextTest extends \TYPO3\CMS\Components\TestingFramework\Core\U ...@@ -98,4 +98,38 @@ class RenderingContextTest extends \TYPO3\CMS\Components\TestingFramework\Core\U
$this->renderingContext->_set('viewHelperVariableContainer', $viewHelperVariableContainer); $this->renderingContext->_set('viewHelperVariableContainer', $viewHelperVariableContainer);
$this->assertSame($viewHelperVariableContainer, $this->renderingContext->getViewHelperVariableContainer()); $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']
];
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment