Actions
Bug #63022
closedNumberRangeValidator doesn't work with integer values.
Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2014-11-17
Due date:
% Done:
0%
Estimated time:
TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
no-brainer
Is Regression:
No
Sprint Focus:
Description
In one of my projects i want to store a persons sex.
I use a integer field. Value 1 = female, value 2 = male.
Here's the property in the model:
/** * sex * * @var integer * @validate NotEmpty, NumberRange(minimum=1,maximum=2) */ protected $sex;
Thing is, the "NumberRange" Validator doesn't cast the min/max options to integer. So the validator compares chars with integers.
So even if the property comes f.e. from a form with a value of 3, the isValid function returns no error.
the line
if ($value < $minimum || $value > $maximum) ...
results in
if ( 3 < '1' || 3 > '2' ) ...
Here's my quick&dirty fix in file extbase/Classes/Validation/Validator/NumberRangeValidator.php
if (isset($this->options['minimum'])) { $minimum = (int)$this->options['minimum']; } elseif (isset($this->options['startRange'])) { $minimum = (int)$this->options['startRange']; } else { $minimum = 0; } if (isset($this->options['maximum'])) { $maximum = (int)$this->options['maximum']; } elseif (isset($this->options['endRange'])) { $maximum = (int)$this->options['endRange']; } else { $maximum = PHP_INT_MAX; }
Actions