[BUGFIX] Wrong result on empty string globalString condition 49/27249/2
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Fri, 5 Jul 2013 21:45:30 +0000 (23:45 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 5 May 2014 18:20:41 +0000 (20:20 +0200)
A TypoScript condition like
"[globalString = GP:anEmptyGetPostVarKey = ]" returns a false
value instead of the expected true value.

Fixes: #45183
Releases: 4.5,6.0, 6.1, 6.2
Change-Id: I114b702f4b5ae5f68236874325e82974a8ba6107
Reviewed-on: https://review.typo3.org/27249
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/backend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php
typo3/sysext/core/Classes/Configuration/TypoScript/ConditionMatching/AbstractConditionMatcher.php
typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php

index bc39a14..84b00c4 100644 (file)
@@ -516,6 +516,19 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         *
         * @test
         */
+       public function globalStringConditionMatchesOnEmptyExpressionWithValueSetToEmptyString() {
+               $testKey = uniqid('test');
+               $_GET = array();
+               $_POST = array($testKey => '');
+               $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . '=]'));
+               $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . ' = ]'));
+       }
+
+       /**
+        * 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]'));
@@ -997,4 +1010,4 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
 }
 
-?>
\ No newline at end of file
+?>
index 82f37c9..f7081bb 100644 (file)
@@ -522,7 +522,9 @@ abstract class AbstractConditionMatcher {
         */
        protected function searchStringWildcard($haystack, $needle) {
                $result = FALSE;
-               if ($needle) {
+               if ($haystack === $needle) {
+                       $result = TRUE;
+               } elseif ($needle) {
                        if (preg_match('/^\\/.+\\/$/', $needle)) {
                                // Regular expression, only "//" is allowed as delimiter
                                $regex = $needle;
index 69e8dc4..bb1d6ec 100644 (file)
@@ -471,6 +471,19 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         *
         * @test
         */
+       public function globalStringConditionMatchesOnEmptyExpressionWithValueSetToEmptyString() {
+               $testKey = uniqid('test');
+               $_GET = array();
+               $_POST = array($testKey => '');
+               $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . '=]'));
+               $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . ' = ]'));
+       }
+
+       /**
+        * 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]'));
@@ -701,4 +714,4 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
 }
 
-?>
\ No newline at end of file
+?>