[BUGFIX] Fix empty globalString LIT condition comparison 59/30559/5
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Wed, 4 Jun 2014 14:40:53 +0000 (16:40 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 20 Jun 2014 22:04:17 +0000 (00:04 +0200)
An empty "LIT:" condition results in NULL, so the strict compare
doesn't match with the empty string.

Solution is to cast the haystack to string before, like it was
done anyway later in the preg_match.

Releases: 6.3, 6.2, 6.1
Resolves: #59344
Change-Id: I1e4b00e454d921eedd0c03a1767d4ec57c321bd7
Reviewed-on: https://review.typo3.org/30559
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Marc Bastian Heinrichs
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/backend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php
typo3/sysext/backend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php
typo3/sysext/core/Classes/Configuration/TypoScript/ConditionMatching/AbstractConditionMatcher.php
typo3/sysext/frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php
typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php

index ca89313..f34f294 100644 (file)
@@ -110,13 +110,12 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
         * Returns GP / ENV vars
         *
         * @param string $var Identifier
-        * @return mixed The value of the variable pointed to.
+        * @return mixed The value of the variable pointed to or NULL if variable did not exist
         * @access private
         */
        protected function getVariable($var) {
                $vars = explode(':', $var, 2);
-               $val = parent::getVariableCommon($vars);
-               return $val;
+               return parent::getVariableCommon($vars);
        }
 
        /**
index 9aa784d..48399f6 100644 (file)
@@ -356,10 +356,10 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function globalVarConditionMatchesOnEqualExpression() {
-               $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]'));
-               $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]'));
-               $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]'));
-               $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]'));
+               $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]'), '1');
+               $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]'), '2');
+               $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]'), '3');
+               $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]'), '4');
        }
 
        /**
@@ -503,6 +503,16 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         *
         * @test
         */
+       public function globalStringConditionMatchesOnEmptyLiteralExpressionWithValueSetToEmptyString() {
+               $this->assertTrue($this->matchCondition->match('[globalString = LIT:=]'));
+               $this->assertTrue($this->matchCondition->match('[globalString = LIT: = ]'));
+       }
+
+       /**
+        * Tests whether string comparison matches.
+        *
+        * @test
+        */
        public function globalStringConditionMatchesWildcardExpression() {
                $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
                $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
index 036cc5d..58517c9 100644 (file)
@@ -287,8 +287,8 @@ abstract class AbstractConditionMatcher {
                                break;
                        case 'useragent':
                                $test = trim($value);
-                               if (strlen($test)) {
-                                       return $this->searchStringWildcard($browserInfo['useragent'], $test);
+                               if ($test !== '') {
+                                       return $this->searchStringWildcard((string)$browserInfo['useragent'], $test);
                                }
                                break;
                        case 'language':
@@ -412,7 +412,7 @@ abstract class AbstractConditionMatcher {
                                foreach ($values as $test) {
                                        $point = strcspn($test, '=');
                                        $theVarName = substr($test, 0, $point);
-                                       $nv = $this->getVariable(trim($theVarName));
+                                       $nv = (string)$this->getVariable(trim($theVarName));
                                        $testValue = substr($test, $point + 1);
                                        if ($this->searchStringWildcard($nv, trim($testValue))) {
                                                return TRUE;
@@ -515,7 +515,7 @@ abstract class AbstractConditionMatcher {
         * Evaluates a $leftValue based on an operator: "<", ">", "<=", ">=", "!=" or "="
         *
         * @param string $test The value to compare with on the form [operator][number]. Eg. "< 123
-        * @param integer $leftValue The value on the left side
+        * @param float $leftValue The value on the left side
         * @return boolean If $value is "50" and $test is "< 123" then it will return TRUE.
         */
        protected function compareNumber($test, $leftValue) {
@@ -587,7 +587,7 @@ abstract class AbstractConditionMatcher {
                                // Replace the marker with .* to match anything (wildcard)
                                $regex = str_replace(array('###MANY###', '###ONE###'), array('.*', '.'), $regex);
                        }
-                       $result = (bool) preg_match($regex, ((string) $haystack));
+                       $result = (bool)preg_match($regex, $haystack);
                }
                return $result;
        }
index aa89c72..8f60daa 100644 (file)
@@ -94,7 +94,7 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
         * Returns GP / ENV / TSFE vars
         *
         * @param string $var Identifier
-        * @return mixed The value of the variable pointed to.
+        * @return mixed The value of the variable pointed to or NULL if variable did not exist
         */
        protected function getVariable($var) {
                $vars = explode(':', $var, 2);
index 2282727..aeceb78 100644 (file)
@@ -478,6 +478,16 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         *
         * @test
         */
+       public function globalStringConditionMatchesOnEmptyLiteralExpressionWithValueSetToEmptyString() {
+               $this->assertTrue($this->matchCondition->match('[globalString = LIT:=]'));
+               $this->assertTrue($this->matchCondition->match('[globalString = LIT: = ]'));
+       }
+
+       /**
+        * Tests whether string comparison matches.
+        *
+        * @test
+        */
        public function globalStringConditionMatchesWildcardExpression() {
                $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
                $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));