#63022NumberRangeValidator doesn't work with integer values.
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;
}Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.