diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php index 6dd8af10b7f0e5d00f4e30aeaf3632d5ba0a3573..ea9be11573461e15f2aad09f75524d8f005c70a1 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php @@ -5905,7 +5905,8 @@ class ContentObjectRenderer if (file_exists(rawurldecode($splitLinkParam[0])) || strpos($linkParameter, '/') !== false) { // Setting title if blank value to link $linkText = $this->parseFallbackLinkTextIfLinkTextIsEmpty($linkText, rawurldecode($linkParameter)); - $this->lastTypoLinkUrl = $this->processUrl(UrlProcessorInterface::CONTEXT_FILE, $GLOBALS['TSFE']->absRefPrefix . $linkParameter, $conf); + $fileUri = (!StringUtility::beginsWith($linkParameter, '/') ? $GLOBALS['TSFE']->absRefPrefix : '') . $linkParameter; + $this->lastTypoLinkUrl = $this->processUrl(UrlProcessorInterface::CONTEXT_FILE, $fileUri, $conf); $this->lastTypoLinkUrl = $this->forceAbsoluteUrl($this->lastTypoLinkUrl, $conf); if (empty($target)) { $target = isset($conf['fileTarget']) ? $conf['fileTarget'] : $tsfe->fileTarget; diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index 0247404cddd777c7519f4fd8189bbd4c33622262..ba46e80f888cd786a70c5760e800de7b819f4969 100755 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -4572,6 +4572,155 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase $this->assertEquals($expectedResult, $this->subject->typoLink($linkText, $configuration)); } + /** + * @return array + */ + public function typolinkReturnsCorrectLinksForFilesWithAbsRefPrefixDataProvider() + { + return array( + 'Link to file' => array( + 'My file', + array( + 'parameter' => 'fileadmin/foo.bar', + ), + '/', + '<a href="/fileadmin/foo.bar">My file</a>', + ), + 'Link to file with longer absRefPrefix' => array( + 'My file', + array( + 'parameter' => 'fileadmin/foo.bar', + ), + '/sub/', + '<a href="/sub/fileadmin/foo.bar">My file</a>', + ), + 'Link to absolute file' => array( + 'My file', + array( + 'parameter' => '/images/foo.bar', + ), + '/', + '<a href="/images/foo.bar">My file</a>', + ), + 'Link to absolute file with longer absRefPrefix' => array( + 'My file', + array( + 'parameter' => '/images/foo.bar', + ), + '/sub/', + '<a href="/images/foo.bar">My file</a>', + ), + 'Link to absolute file with identical longer absRefPrefix' => array( + 'My file', + array( + 'parameter' => '/sub/fileadmin/foo.bar', + ), + '/sub/', + '<a href="/sub/fileadmin/foo.bar">My file</a>', + ), + 'Link to file with empty absRefPrefix' => array( + 'My file', + array( + 'parameter' => 'fileadmin/foo.bar', + ), + '', + '<a href="fileadmin/foo.bar">My file</a>', + ), + 'Link to absolute file with empty absRefPrefix' => array( + 'My file', + array( + 'parameter' => '/fileadmin/foo.bar', + ), + '', + '<a href="/fileadmin/foo.bar">My file</a>', + ), + 'Link to file with attributes with absRefPrefix' => array( + 'My file', + array( + 'parameter' => 'fileadmin/foo.bar', + 'ATagParams' => 'class="file-class"', + 'fileTarget' => '_blank', + 'title' => 'Title of the file', + ), + '/', + '<a href="/fileadmin/foo.bar" title="Title of the file" target="_blank" class="file-class">My file</a>', + ), + 'Link to file with attributes with longer absRefPrefix' => array( + 'My file', + array( + 'parameter' => 'fileadmin/foo.bar', + 'ATagParams' => 'class="file-class"', + 'fileTarget' => '_blank', + 'title' => 'Title of the file', + ), + '/sub/', + '<a href="/sub/fileadmin/foo.bar" title="Title of the file" target="_blank" class="file-class">My file</a>', + ), + 'Link to absolute file with attributes with absRefPrefix' => array( + 'My file', + array( + 'parameter' => '/images/foo.bar', + 'ATagParams' => 'class="file-class"', + 'fileTarget' => '_blank', + 'title' => 'Title of the file', + ), + '/', + '<a href="/images/foo.bar" title="Title of the file" target="_blank" class="file-class">My file</a>', + ), + 'Link to absolute file with attributes with longer absRefPrefix' => array( + 'My file', + array( + 'parameter' => '/images/foo.bar', + 'ATagParams' => 'class="file-class"', + 'fileTarget' => '_blank', + 'title' => 'Title of the file', + ), + '/sub/', + '<a href="/images/foo.bar" title="Title of the file" target="_blank" class="file-class">My file</a>', + ), + 'Link to absolute file with attributes with identical longer absRefPrefix' => array( + 'My file', + array( + 'parameter' => '/sub/fileadmin/foo.bar', + 'ATagParams' => 'class="file-class"', + 'fileTarget' => '_blank', + 'title' => 'Title of the file', + ), + '/sub/', + '<a href="/sub/fileadmin/foo.bar" title="Title of the file" target="_blank" class="file-class">My file</a>', + ), + ); + } + + /** + * @test + * @param string $linkText + * @param array $configuration + * @param string $absRefPrefix + * @param string $expectedResult + * @dataProvider typolinkReturnsCorrectLinksForFilesWithAbsRefPrefixDataProvider + */ + public function typolinkReturnsCorrectLinksForFilesWithAbsRefPrefix($linkText, $configuration, $absRefPrefix, $expectedResult) + { + $templateServiceObjectMock = $this->getMock(TemplateService::class, array('dummy')); + $templateServiceObjectMock->setup = array( + 'lib.' => array( + 'parseFunc.' => $this->getLibParseFunc(), + ), + ); + $typoScriptFrontendControllerMockObject = $this->getMock(TypoScriptFrontendController::class, array(), array(), '', false); + $typoScriptFrontendControllerMockObject->config = array( + 'config' => array(), + 'mainScript' => 'index.php', + ); + $typoScriptFrontendControllerMockObject->tmpl = $templateServiceObjectMock; + $GLOBALS['TSFE'] = $typoScriptFrontendControllerMockObject; + $GLOBALS['TSFE']->absRefPrefix = $absRefPrefix; + $this->subject->_set('typoScriptFrontendController', $typoScriptFrontendControllerMockObject); + + $this->assertEquals($expectedResult, $this->subject->typoLink($linkText, $configuration)); + } + /** * @test */