[BUGFIX] Add trim to modificators in TS-Parser 88/33288/6
authorStefan Froemken <froemken@gmail.com>
Mon, 13 Oct 2014 09:17:22 +0000 (11:17 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 13 Oct 2014 21:53:34 +0000 (23:53 +0200)
It is documented that modificators are trimmed in
TypoScriptParser. But since #54856 they aren't trimmed anymore.
That's why f.e. "addToList (value)" will not be executed.

Resolves: #62188
Related: #54856
Releases: master,6.2
Change-Id: I3828b22a836656ec808ac5d770d58803b9195102
Reviewed-on: http://review.typo3.org/33288
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php
typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php

index 07f57fa..16254e2 100644 (file)
@@ -369,7 +369,7 @@ class TypoScriptParser {
                                                                } else {
                                                                        // Checking for special TSparser properties (to change TS values at parsetime)
                                                                        $match = array();
-                                                                       if ($line[0] === ':' && preg_match('/^:=\\s*([^\\(]+)\\s*\\((.*)\\).*/', $line, $match)) {
+                                                                       if ($line[0] === ':' && preg_match('/^:=\\s*([[:alpha:]]+)\\s*\\((.*)\\).*/', $line, $match)) {
                                                                                $tsFunc = $match[1];
                                                                                $tsFuncArg = $match[2];
                                                                                list($currentValue) = $this->getVal($objStrName, $setup);
@@ -508,7 +508,7 @@ class TypoScriptParser {
                                $newValue = str_replace($fromStr, $toStr, $currentValue);
                                break;
                        case 'addToList':
-                               $newValue = ((string)$currentValue !== '' ? $currentValue . ',' : '') . trim($modifierArgument);
+                               $newValue = ((string)$currentValue !== '' ? $currentValue . ',' : '') . $modifierArgument;
                                break;
                        case 'removeFromList':
                                $existingElements = GeneralUtility::trimExplode(',', $currentValue);
index ecf5ef8..b531cc0 100644 (file)
@@ -107,6 +107,12 @@ class TypoScriptParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                '789',
                                '123,456,789',
                        ),
+                       'addToList adds at end of existing list including white-spaces' => array(
+                               'addToList',
+                               '123,456',
+                               ' 789 , 32 , 12 ',
+                               '123,456, 789 , 32 , 12 ',
+                       ),
                        'addToList adds nothing' => array(
                                'addToList',
                                '123,456',
@@ -607,30 +613,48 @@ class TypoScriptParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                        ),
                                ),
                        ),
-                   'key with colon' => array(
+                       'key with colon' => array(
                                'some:key = is valid',
                                array(
                                        'some:key' => 'is valid'
                                )
-                   ),
-                   'special operator' => array(
-                           'some := addToList(a)',
-                           array(
-                                   'some' => 'a'
-                           )
-                   ),
-                   'special operator and colon, no spaces' => array(
-                           'some:key:=addToList(a)',
-                           array(
-                                   'some:key' => 'a'
-                           )
-                   ),
-                   'key with all special symbols' => array(
-                           'someSpecial\\_:-\\.Chars = is valid',
-                           array(
-                                   'someSpecial\\_:-.Chars' => 'is valid'
-                           )
-                   ),
+                       ),
+                       'special operator' => array(
+                               'some := addToList(a)',
+                               array(
+                                       'some' => 'a'
+                               )
+                       ),
+                       'special operator with white-spaces' => array(
+                               'some := addToList (a)',
+                               array(
+                                       'some' => 'a'
+                               )
+                       ),
+                       'special operator with tabs' => array(
+                               'some :=        addToList       (a)',
+                               array(
+                                       'some' => 'a'
+                               )
+                       ),
+                       'special operator with white-spaces and tabs in value' => array(
+                               'some := addToList( a, b,       c )',
+                               array(
+                                       'some' => 'a, b,        c'
+                               )
+                       ),
+                       'special operator and colon, no spaces' => array(
+                               'some:key:=addToList(a)',
+                               array(
+                                       'some:key' => 'a'
+                               )
+                       ),
+                       'key with all special symbols' => array(
+                               'someSpecial\\_:-\\.Chars = is valid',
+                               array(
+                                       'someSpecial\\_:-.Chars' => 'is valid'
+                               )
+                       ),
                );
        }