[BUGFIX] Correctly evaluate LIT:0 in TS conditions 64/56464/2
authorMarkus Klein <markus.klein@typo3.org>
Tue, 27 Mar 2018 19:59:19 +0000 (21:59 +0200)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Thu, 29 Mar 2018 08:12:18 +0000 (10:12 +0200)
Handle LIT:0 used in TypoScript conditions such that is evaluates
to '0' instead of null.
This makes comparisons for equality working.

Resolves: #84543
Releases: master, 8.7
Change-Id: I5eb16d556098179605646faf696f9defaf6195ac
Reviewed-on: https://review.typo3.org/56464
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
typo3/sysext/backend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php
typo3/sysext/core/Classes/Configuration/TypoScript/ConditionMatching/AbstractConditionMatcher.php

index 4e997d1..03c1957 100644 (file)
@@ -272,6 +272,8 @@ class ConditionMatcherTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCas
         $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');
+        $this->assertTrue($this->matchCondition->match('[globalVar = LIT:0 = 0]'), '5');
+        $this->assertTrue($this->matchCondition->match('[globalVar = LIT:0 == 0]'), '6');
     }
 
     /**
@@ -300,6 +302,7 @@ class ConditionMatcherTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCas
     {
         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]'));
         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]'));
+        $this->assertTrue($this->matchCondition->match('[globalVar = LIT:0 != 1]'));
     }
 
     /**
@@ -332,6 +335,7 @@ class ConditionMatcherTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCas
     {
         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]'));
         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]'));
+        $this->assertTrue($this->matchCondition->match('[globalVar = LIT:0 < 1]'));
     }
 
     /**
@@ -356,6 +360,7 @@ class ConditionMatcherTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCas
     {
         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]'));
         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]'));
+        $this->assertTrue($this->matchCondition->match('[globalVar = LIT:1 > 0]'));
     }
 
     /**
index 633a7de..b5bb508 100644 (file)
@@ -434,13 +434,16 @@ abstract class AbstractConditionMatcher
     protected function getVariableCommon(array $vars)
     {
         $value = null;
+        $namespace = trim($vars[0]);
         if (count($vars) === 1) {
             $value = $this->getGlobal($vars[0]);
+        } elseif ($namespace === 'LIT') {
+            $value = trim($vars[1]);
         } else {
             $splitAgain = explode('|', $vars[1], 2);
             $k = trim($splitAgain[0]);
             if ($k) {
-                switch ((string)trim($vars[0])) {
+                switch ($namespace) {
                     case 'GP':
                         $value = GeneralUtility::_GP($k);
                         break;
@@ -453,9 +456,6 @@ abstract class AbstractConditionMatcher
                     case 'IENV':
                         $value = GeneralUtility::getIndpEnv($k);
                         break;
-                    case 'LIT':
-                        return trim($vars[1]);
-                        break;
                     default:
                         return null;
                 }