Skip to content
Snippets Groups Projects
Commit 61180b34 authored by Elias Häußler's avatar Elias Häußler Committed by Daniel Goerz
Browse files

[BUGFIX] Ensure pageUid of RedirectFinisher can be parsed correctly

With #92112, parsing of the pageUid option of the RedirectFinisher has
been restricted to accept only strings as option value. Prior to this
change, one could also define integer values. The previous behavior has
now been restored by explicitly parsing the option value as string and
then parsing it back to an integer.

Resolves: #92800
Related: #92112
Releases: master, 10.4
Change-Id: I88992b309e09757ae24348c6066294effb209505
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66620


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: default avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: default avatarDaniel Goerz <daniel.goerz@posteo.de>
parent 8e756135
No related merge requests found
......@@ -69,8 +69,7 @@ class RedirectFinisher extends AbstractFinisher
$this->uriBuilder->setRequest($this->request);
$pageUid = $this->parseOption('pageUid');
$pageUid = is_string($pageUid) ? $pageUid : '';
$pageUid = (int)str_replace('pages_', '', $pageUid);
$pageUid = (int)str_replace('pages_', '', (string)$pageUid);
$additionalParameters = $this->parseOption('additionalParameters');
$additionalParameters = is_string($additionalParameters) ? $additionalParameters : '';
$additionalParameters = '&' . ltrim($additionalParameters, '&');
......
<?php
declare(strict_types=1);
/*
* 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!
*/
namespace TYPO3\CMS\Form\Tests\Unit\Domain\Finishers;
use Prophecy\Argument;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Object\Exception;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Form\Domain\Finishers\FinisherContext;
use TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher;
use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
use TYPO3\CMS\Form\Service\TranslationService;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/**
* Test case
*/
class RedirectFinisherTest extends UnitTestCase
{
protected $resetSingletonInstances = true;
/**
* @test
* @dataProvider pageUidOptionForFinisherAcceptsVariousPageRepresentationsDataProvider
* @param string|int|null $pageUid
* @param int $expectedPage
* @throws Exception
*/
public function pageUidOptionForFinisherAcceptsVariousPageRepresentations($pageUid, int $expectedPage): void
{
$uriPrefix = 'https://site.test/?id=';
$contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class);
$contentObjectRendererProphecy->typoLink_URL(Argument::type('array'))->will(function ($arguments) use ($uriPrefix) {
return $uriPrefix . $arguments[0]['parameter'];
});
$tsfeProphecy = $this->prophesize(TypoScriptFrontendController::class);
$tsfeProphecy->cObj = $contentObjectRendererProphecy->reveal();
$GLOBALS['TSFE'] = $tsfeProphecy->reveal();
$redirectFinisherMock = $this->getAccessibleMock(RedirectFinisher::class, null, [], '', false);
$redirectFinisherMock->_set('options', [
'pageUid' => $pageUid,
]);
$formRuntimeProphecy = $this->prophesize(FormRuntime::class);
$formRuntimeProphecy->getRequest()->willReturn(new Request());
$formRuntimeProphecy->getResponse()->willReturn(new Response());
$finisherContextProphecy = $this->prophesize(FinisherContext::class);
$finisherContextProphecy->getFormRuntime()->willReturn($formRuntimeProphecy->reveal());
$finisherContextProphecy->cancel()->shouldBeCalledOnce();
$translationServiceProphecy = $this->prophesize(TranslationService::class);
$translationServiceProphecy->translateFinisherOption(Argument::cetera())->willReturnArgument(3);
$objectManagerProphecy = $this->prophesize(ObjectManager::class);
$objectManagerProphecy->get(UriBuilder::class)->willReturn(new UriBuilder());
$objectManagerProphecy->get(TranslationService::class)->willReturn($translationServiceProphecy->reveal());
GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
$redirectFinisherMock->injectObjectManager($objectManagerProphecy->reveal());
try {
$redirectFinisherMock->execute($finisherContextProphecy->reveal());
self::fail('RedirectFinisher did not throw expected exception.');
} /** @noinspection PhpRedundantCatchClauseInspection */ catch (StopActionException $e) {
$response = $e->getResponse();
self::assertSame($uriPrefix . $expectedPage, $response->getHeader('Location')[0]);
}
}
public function pageUidOptionForFinisherAcceptsVariousPageRepresentationsDataProvider(): array
{
return [
'null' => [
null,
1,
],
'no page' => [
'',
1,
],
'page as integer' => [
3,
3,
],
'page as string' => [
'3',
3,
],
'page with table prefix' => [
'pages_3',
3,
],
];
}
}
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