[BUGFIX] Numeric check for upper/lower bound of flexform-values 02/19702/2
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 10 Dec 2012 11:23:31 +0000 (12:23 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Tue, 9 Apr 2013 12:47:09 +0000 (14:47 +0200)
The range-check in Flexforms uses the same code as for normal
tables. Normally an integer field would be of type integer.
But in Flexforms the value is a string as is the value in DS.

Change-Id: I3512a961780a4bef91e04f61b8b9547f43f28f3e
Fixes: #15771
Releases: 4.5, 4.6, 4.7, 6.0, 6.1
Reviewed-on: https://review.typo3.org/19702
Reviewed-by: Nicole Cordes
Reviewed-by: Georg Ringer
Tested-by: Georg Ringer
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php

index 84e189b..08008e7 100644 (file)
@@ -1487,10 +1487,10 @@ class DataHandler {
                }
                // Checking range of value:
                if ($tcaFieldConf['range'] && $value != $tcaFieldConf['checkbox'] && intval($value) !== intval($tcaFieldConf['default'])) {
-                       if (isset($tcaFieldConf['range']['upper']) && $value > $tcaFieldConf['range']['upper']) {
+                       if (isset($tcaFieldConf['range']['upper']) && intval($value) > intval($tcaFieldConf['range']['upper'])) {
                                $value = $tcaFieldConf['range']['upper'];
                        }
-                       if (isset($tcaFieldConf['range']['lower']) && $value < $tcaFieldConf['range']['lower']) {
+                       if (isset($tcaFieldConf['range']['lower']) && intval($value) < intval($tcaFieldConf['range']['lower'])) {
                                $value = $tcaFieldConf['range']['lower'];
                        }
                }
@@ -7173,4 +7173,4 @@ class DataHandler {
 }
 
 
-?>
\ No newline at end of file
+?>
index 8b5d200..a21e99f 100644 (file)
@@ -155,6 +155,45 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                }
        }
 
+       /**
+        * Data provider for inputValueCheckRecognizesStringValuesAsIntegerValuesCorrectly
+        *
+        * @return array
+        */
+       public function inputValuesStringsDataProvider() {
+               return array(
+                       '"0" returns zero as integer' => array(
+                               '0',
+                               0
+                       ),
+                       '"-1999999" is interpreted correctly as -1999999 and is lot lower then -200000' => array(
+                               '-1999999',
+                               -1999999
+                       ),
+                       '"3000000" is interpreted correctly as 3000000 but is higher then 200000 and set to 200000' => array(
+                               '3000000',
+                               2000000
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider inputValuesStringsDataProvider
+        */
+       public function inputValueCheckRecognizesStringValuesAsIntegerValuesCorrectly($value, $expectedReturnValue) {
+               $tcaFieldConf = array(
+                       'input' => array(),
+                       'eval' => 'int',
+                       'range' => array(
+                               'lower' => '-2000000',
+                               'upper' => '2000000'
+                       )
+               );
+               $returnValue = $this->fixture->checkValue_input(array(), $value, $tcaFieldConf, array());
+               $this->assertSame($returnValue['value'], $expectedReturnValue);
+       }
+
        ///////////////////////////////////////////
        // Tests concerning checkModifyAccessList
        ///////////////////////////////////////////