Skip to content

Commit

Permalink
[BUGFIX] Correctly evaluate LIT:0 in TS conditions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
liayn authored and tmotyl committed Mar 29, 2018
1 parent 2ee2312 commit 084a75e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Expand Up @@ -272,6 +272,8 @@ public function globalVarConditionMatchesOnEqualExpression()
$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');
}

/**
Expand Down Expand Up @@ -300,6 +302,7 @@ public function globalVarConditionMatchesOnNotEqualExpression()
{
$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]'));
}

/**
Expand Down Expand Up @@ -332,6 +335,7 @@ public function globalVarConditionMatchesOnLowerThanExpression()
{
$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]'));
}

/**
Expand All @@ -356,6 +360,7 @@ public function globalVarConditionMatchesOnGreaterThanExpression()
{
$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]'));
}

/**
Expand Down
Expand Up @@ -434,13 +434,16 @@ protected function parseUserFuncArguments($arguments)
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;
Expand All @@ -453,9 +456,6 @@ protected function getVariableCommon(array $vars)
case 'IENV':
$value = GeneralUtility::getIndpEnv($k);
break;
case 'LIT':
return trim($vars[1]);
break;
default:
return null;
}
Expand Down

0 comments on commit 084a75e

Please sign in to comment.