Project

General

Profile

Actions

Bug #63022

closed

NumberRangeValidator doesn't work with integer values.

Added by Dennis Biedermann about 10 years ago. Updated almost 8 years ago.

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 #1

Updated by Alexandru Catalin Dinis over 9 years ago

Hello,
I've checked the reported bug and I figured out that the validator does not compares chars with integers,because it checks if the input is numeric (it uses the is_numeric function) before.
I think this bug should be closed.

Actions #2

Updated by Riccardo De Contardi almost 8 years ago

  • Status changed from New to Closed

Thank you for your findings and sorry for the very late answer. I close it.
Feel free to reopen it if you think that this is the wrong decision or new information comes out about this topic.

Thanks

Actions

Also available in: Atom PDF