[BUGFIX] BooleanValidator skips Validation with missing compare param
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Tue, 5 Mar 2013 19:18:50 +0000 (20:18 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Wed, 6 Mar 2013 06:06:00 +0000 (07:06 +0100)
If no 'is' parameter is given, BooleanValidator skips testing and
returns TRUE. So all properties of type boolean not explicit assigned
to validation pass the test without limitation.

Fixes: #46031
Releases: 6.1
Change-Id: Ib484e35fbb90e3bb878ef5114cf65c05975d0d6e
Reviewed-on: https://review.typo3.org/18705
Reviewed-by: Jost Baron
Tested-by: Jost Baron
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Validation/Validator/BooleanValidator.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BooleanValidatorTest.php

index e17dd6d..e2fb829 100644 (file)
@@ -44,6 +44,9 @@ class BooleanValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractV
         * @return boolean TRUE if the value is within the range, otherwise FALSE
         */
        public function isValid($value) {
+               if (!isset($this->options['is'])) {
+                       return TRUE;
+               }
                switch (strtolower((string)$this->options['is'])) {
                        case 'true':
                        case '1':
index 78b6f72..03bd03b 100644 (file)
@@ -93,6 +93,14 @@ class BooleanValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Vali
                $this->validatorOptions(array('is' => TRUE));
                $this->assertTrue($this->validator->validate('a string')->hasErrors());
        }
+
+       /**
+        * @test
+        */
+       public function booleanValidatorReturnsTrueIfNoParameterIsGiven() {
+               $this->validatorOptions(array());
+               $this->assertFalse($this->validator->validate(TRUE)->hasErrors());
+       }
 }
 
 ?>