[BUGFIX] Wrong result on empty string globalString condition 79/21979/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>
Sat, 1 Feb 2014 22:29:29 +0000 (23:29 +0100)
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/21979
Tested-by: Philipp Gampe
Reviewed-by: Philipp Gampe
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 b76bb9d..6a648a4 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]'));
index d0f9753..15583bf 100644 (file)
@@ -572,7 +572,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 4ef56a2..9554abf 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]'));