From 78af7508173c357bc3de947500abd4b52f7ac82e Mon Sep 17 00:00:00 2001 From: Markus Klein Date: Sat, 28 Jun 2014 17:19:32 +0200 Subject: [PATCH] [BUGFIX] Allow colon in TypoScript key 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/31389 Reviewed-by: Christian Kuhn Tested-by: Christian Kuhn --- .../TypoScript/Parser/TypoScriptParser.php | 10 +++++--- .../Parser/TypoScriptParserTest.php | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php b/typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php index 18ebb73d14eb..30f44d216c5b 100644 --- a/typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php +++ b/typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php @@ -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) { diff --git a/typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php b/typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php index 049b8fa5a0f2..ecf5ef8dc412 100644 --- a/typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php +++ b/typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php @@ -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' + ) + ), ); } -- 2.20.1