diff --git a/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php b/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php index 9dc30fcb96a8b64fd1425ab4a55dd503eee9be15..49194fbc58a43467e1f532cc32985d7977138f4c 100644 --- a/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php +++ b/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php @@ -224,7 +224,7 @@ class PageLinkBuilder extends AbstractTypolinkBuilder if (!trim($currentQueryParams)) { list(, $URLparams) = explode('?', $url); - list($URLparams) = explode('#', $URLparams); + list($URLparams) = explode('#', (string)$URLparams); parse_str($URLparams . $LD['orig_type'], $URLparamsArray); // Type nums must match as well as page ids if ((int)$URLparamsArray['type'] === (int)$tsfe->type) { diff --git a/typo3/sysext/frontend/Tests/Functional/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Functional/ContentObject/ContentObjectRendererTest.php index cd13ccc07f0648b7f861ff3a8c251de09b64cbf7..295bb3c89f827819cbbbe141011623bd5c134e7d 100644 --- a/typo3/sysext/frontend/Tests/Functional/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Functional/ContentObject/ContentObjectRendererTest.php @@ -469,6 +469,61 @@ class ContentObjectRendererTest extends \TYPO3\TestingFramework\Core\Functional\ $this->assertEquals($expectedResult, $subject->typoLink($linkText, $configuration)); } + /** + * @test + */ + public function typolinkReturnsCorrectLinkForSectionToHomePageWithUrlRewriting() + { + $pageRepositoryMockObject = $this->getMockBuilder(PageRepository::class) + ->setMethods(['getPage']) + ->getMock(); + $pageRepositoryMockObject->expects($this->any())->method('getPage')->willReturn([ + 'uid' => 1, + 'title' => 'Page title', + ]); + + $templateServiceMockObject = $this->getMockBuilder(TemplateService::class) + ->setMethods(['linkData']) + ->getMock(); + $templateServiceMockObject->setup = [ + 'lib.' => [ + 'parseFunc.' => $this->getLibParseFunc(), + ], + ]; + $templateServiceMockObject->expects($this->once())->method('linkData')->willReturn([ + 'url' => '/index.php?id=1', + 'target' => '', + 'type' => '', + 'orig_type' => '', + 'no_cache' => '', + 'linkVars' => '', + 'sectionIndex' => '', + 'totalURL' => '/', + ]); + + $typoScriptFrontendController = GeneralUtility::makeInstance( + TypoScriptFrontendController::class, + null, + 1, + 0 + ); + $typoScriptFrontendController->config = [ + 'config' => [], + 'mainScript' => 'index.php', + ]; + $typoScriptFrontendController->sys_page = $pageRepositoryMockObject; + $typoScriptFrontendController->tmpl = $templateServiceMockObject; + $GLOBALS['TSFE'] = $typoScriptFrontendController; + + $configuration = [ + 'parameter' => 1, + 'section' => 'content', + ]; + + $subject = GeneralUtility::makeInstance(ContentObjectRenderer::class); + $this->assertEquals('<a href="#content">Page title</a>', $subject->typoLink('', $configuration)); + } + /** * @return array */