[+BUGFIX] Fluid (Core): Boolean expressions can now contain negative numbers. Resolve...
authorSebastian Kurfürst <sebastian@typo3.org>
Thu, 26 Aug 2010 08:13:05 +0000 (08:13 +0000)
committerSebastian Kurfürst <sebastian@typo3.org>
Thu, 26 Aug 2010 08:13:05 +0000 (08:13 +0000)
Boolean expressions with negative numbers did not work so far.
Now, they work as expected. Example from Viewhelpertest which displayed
a wrong result before, and now displays the correct result:

<f:if condition="{testVariables.number.minusOne} < -1.1">
<f:then>Then part!</f:then>
<f:else>Else part!</f:else>
</f:if>

Issue: #9434

typo3/sysext/fluid/Classes/Core/Parser/SyntaxTree/ViewHelperNode.php
typo3/sysext/fluid/Tests/Unit/Core/Parser/SyntaxTree/ViewHelperNodeComparatorTest.php

index baf654d..860f8fd 100644 (file)
@@ -73,8 +73,12 @@ class Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode extends Tx_Fluid_Core_Parse
                (?:               # start repeat
                        COMPARATORS   # We allow all comparators
                        |\s*          # Arbitary spaces
-                       |[0-9]        # Numbers
-                       |\\.          # And the dot.
+                       |-?           # Numbers, possibly with the "minus" symbol in front.
+                               [0-9]+    # some digits
+                               (?:       # and optionally a dot, followed by some more digits
+                                       \\.
+                                       [0-9]+
+                               )?
                )*
                $/x';
 
index 438a969..a8fc8e4 100644 (file)
@@ -266,6 +266,16 @@ class Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNodeComparatorTest extends Tx_Ex
                $this->assertFalse($this->viewHelperNode->_call('evaluateBooleanExpression', $rootNode, $this->renderingContext));
        }
 
+       /**
+        * @test
+        * @author Sebastian Kurfürst <sebastian@typo3.org>
+        */
+       public function lessOrEqualsReturnFalseIfComparingWithANegativeNumber() {
+               $rootNode = new Tx_Fluid_Core_Parser_SyntaxTree_RootNode();
+               $rootNode->addChildNode(new Tx_Fluid_Core_Parser_SyntaxTree_TextNode('11 <= -2.1'));
+
+               $this->assertFalse($this->viewHelperNode->_call('evaluateBooleanExpression', $rootNode, $this->renderingContext));
+       }
 }
 
 ?>
\ No newline at end of file