diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php index 6038dfcadfed147819f6f279ee4122f764dfaec0..82cfecb95ee4c4cf2b4d1ca008b916e263745eda 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php @@ -5606,6 +5606,15 @@ class ContentObjectRenderer 'TYPE' => $linkDetails['type'] ]; + // Ensure "href" is not in the list of aTagParams to avoid double tags, usually happens within buggy parseFunc settings + if (!empty($finalTagParts['aTagParams'])) { + $aTagParams = GeneralUtility::get_tag_attributes($finalTagParts['aTagParams']); + if (isset($aTagParams['href'])) { + unset($aTagParams['href']); + $finalTagParts['aTagParams'] = GeneralUtility::implodeAttributes($aTagParams); + } + } + // Building the final <a href=".."> tag $tagAttributes = []; @@ -5660,7 +5669,9 @@ class ContentObjectRenderer $tagAttributes['class'] = htmlspecialchars($resolvedLinkParameters['class']); } - $finalAnchorTag = '<a ' . GeneralUtility::implodeAttributes($tagAttributes) . $finalTagParts['aTagParams'] . '>'; + // Prevent trouble with double and missing spaces between attributes and merge params before implode + $finalTagAttributes = array_merge($tagAttributes, GeneralUtility::get_tag_attributes($finalTagParts['aTagParams'])); + $finalAnchorTag = '<a ' . GeneralUtility::implodeAttributes($finalTagAttributes) . '>'; if (!empty($finalTagParts['aTagParams'])) { $tagAttributes = array_merge($tagAttributes, GeneralUtility::get_tag_attributes($finalTagParts['aTagParams'])); diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index 98f026a7169a2812f333bfe62f29163900311b3e..e2b8171a17310cbf6c86c73890653ecda1451378 100644 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -2747,6 +2747,56 @@ class ContentObjectRendererTest extends \TYPO3\TestingFramework\Core\Unit\UnitTe ], '<a href="fileadmin/foo.bar" title="Title of the file" target="_blank" class="file-class">My file</a>', ], + 'Link to file with attributes and additional href' => [ + 'My file', + [ + 'parameter' => 'fileadmin/foo.bar', + 'ATagParams' => 'href="foo-bar"', + 'fileTarget' => '_blank', + 'title' => 'Title of the file', + ], + '<a href="fileadmin/foo.bar" title="Title of the file" target="_blank">My file</a>', + ], + 'Link to file with attributes and additional href and class' => [ + 'My file', + [ + 'parameter' => 'fileadmin/foo.bar', + 'ATagParams' => 'href="foo-bar" 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 and additional class and href' => [ + 'My file', + [ + 'parameter' => 'fileadmin/foo.bar', + 'ATagParams' => 'class="file-class" href="foo-bar"', + '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 and additional class and href and title' => [ + 'My file', + [ + 'parameter' => 'fileadmin/foo.bar', + 'ATagParams' => 'class="file-class" href="foo-bar" title="foo-bar"', + 'fileTarget' => '_blank', + 'title' => 'Title of the file', + ], + '<a href="fileadmin/foo.bar" title="foo-bar" target="_blank" class="file-class">My file</a>', + ], + 'Link to file with attributes and empty ATagParams' => [ + 'My file', + [ + 'parameter' => 'fileadmin/foo.bar', + 'ATagParams' => '', + 'fileTarget' => '_blank', + 'title' => 'Title of the file', + ], + '<a href="fileadmin/foo.bar" title="Title of the file" target="_blank">My file</a>', + ], 'Link to file with attributes in parameter' => [ 'My file', [