[BUGFIX] Prevent leading space for empty ATagParams 54/23954/3
authorAlexander Stehlik <alexander.stehlik@googlemail.com>
Sun, 22 Sep 2013 09:08:57 +0000 (11:08 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 23 Sep 2013 21:49:53 +0000 (23:49 +0200)
Currently a leading space will be returned by the ATagParams handler when
the $addGlobal parameter is TRUE.

This patch trims any space if no ATagParams have been configured.

Resolves: #52171
Releases: 6.2
Change-Id: I53b3723e530beb96ff0dc9606963c6d9928d4478
Reviewed-on: https://review.typo3.org/23954
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index 55f16ea..c23ad7b 100644 (file)
@@ -1610,6 +1610,12 @@ class ContentObjectRenderer {
                                $aTagParams = $processor->process($_params, $this);
                        }
                }
+
+               $aTagParams = trim($aTagParams);
+               if (!empty($aTagParams)) {
+                       $aTagParams = ' ' . $aTagParams;
+               }
+
                return $aTagParams;
        }
 
index 45ac75b..eaf84c8 100644 (file)
@@ -1981,6 +1981,33 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $expectedResult = '0,42,719,321,17';
                $this->assertEquals($expectedResult, $result);
        }
+
+       /**
+        * @test
+        */
+       public function aTagParamsHasLeadingSpaceIfNotEmpty() {
+               $aTagParams = $this->cObj->getATagParams(array('ATagParams' => 'data-test="testdata"'));
+               $this->assertEquals(' data-test="testdata"', $aTagParams );
+       }
+
+       /**
+        * @test
+        */
+       public function aTagParamsHaveSpaceBetweenLocalAndGlobalParams() {
+               $GLOBALS['TSFE']->ATagParams = 'data-global="dataglobal"';
+               $aTagParams = $this->cObj->getATagParams(array('ATagParams' => 'data-test="testdata"'));
+               $this->assertEquals(' data-global="dataglobal" data-test="testdata"', $aTagParams );
+       }
+
+       /**
+        * @test
+        */
+       public function aTagParamsHasNoLeadingSpaceIfEmpty() {
+               // make sure global ATagParams are empty
+               $GLOBALS['TSFE']->ATagParams = '';
+               $aTagParams = $this->cObj->getATagParams(array('ATagParams' => ''));
+               $this->assertEquals('', $aTagParams);
+       }
 }
 
 ?>