[BUGFIX] Allow colon in TypoScript key 93/31193/7
authorMarkus Klein <klein.t3@mfc-linz.at>
Sat, 28 Jun 2014 15:19:32 +0000 (17:19 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 6 Jul 2014 14:38:10 +0000 (16:38 +0200)
The TypoScript parser does not properly parse the := operator.
It searches for : only and hence wrongly breaks a TypoScript key apart.

Fix this by detecting the full operator sequence ":=", do not rely
on ":" only.

Resolves: #59965
Releases: 6.3, 6.2
Change-Id: I6401c87b45432d4d74c4092edeb333d4d9d5914e
Reviewed-on: https://review.typo3.org/31193
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
Tested-by: Wouter Wolters
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Stefan Neufeind
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php
typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php

index 18ebb73..30f44d2 100644 (file)
@@ -342,7 +342,11 @@ class TypoScriptParser {
                                        } elseif ($line[0] !== '}' && $line[0] !== '#' && $line[0] !== '/') {
                                                // If not brace-end or comment
                                                // Find object name string until we meet an operator
-                                               $varL = strcspn($line, TAB . ' {=<>:(');
+                                               $varL = strcspn($line, TAB . ' {=<>(');
+                                               // check for special ":=" operator
+                                               if ($varL > 0 && substr($line, $varL-1, 2) === ':=') {
+                                                       --$varL;
+                                               }
                                                // also remove tabs after the object string name
                                                $objStrName = substr($line, 0, $varL);
                                                if ($this->syntaxHighLight) {
@@ -350,8 +354,8 @@ class TypoScriptParser {
                                                }
                                                if ($objStrName !== '') {
                                                        $r = array();
-                                                       if ($this->strict && preg_match('/[^[:alnum:]_\\\\\\.-]/i', $objStrName, $r)) {
-                                                               $this->error('Line ' . ($this->lineNumberOffset + $this->rawP - 1) . ': Object Name String, "' . htmlspecialchars($objStrName) . '" contains invalid character "' . $r[0] . '". Must be alphanumeric or one of: "_-\\."');
+                                                       if ($this->strict && preg_match('/[^[:alnum:]_\\\\\\.:-]/i', $objStrName, $r)) {
+                                                               $this->error('Line ' . ($this->lineNumberOffset + $this->rawP - 1) . ': Object Name String, "' . htmlspecialchars($objStrName) . '" contains invalid character "' . $r[0] . '". Must be alphanumeric or one of: "_:-\\."');
                                                        } else {
                                                                $line = ltrim(substr($line, $varL));
                                                                if ($this->syntaxHighLight) {
index 049b8fa..ecf5ef8 100644 (file)
@@ -607,6 +607,30 @@ class TypoScriptParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                        ),
                                ),
                        ),
+                   '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'
+                           )
+                   ),
                );
        }