[BUGFIX] Only output href attribute once in typolink() 23/52323/5
authorBenni Mack <benni@typo3.org>
Mon, 3 Apr 2017 07:55:52 +0000 (09:55 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Mon, 3 Apr 2017 11:22:23 +0000 (13:22 +0200)
When lib.parseFunc_RTE is set for ATagParams = data:allParams
for rendering anchor tags, href="" is added twice.

Anchor tags filter out additional href="" tags.

Resolves: #80373
Releases: master
Change-Id: Ie5c0124f6f5dcd96d41b230e11d8317febaebe30
Reviewed-on: https://review.typo3.org/52323
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index 6038dfc..82cfecb 100644 (file)
@@ -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']));
index 98f026a..e2b8171 100644 (file)
@@ -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',
                 [