mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Add type check for between comparison
Return 0 if $value is not numeric value
This commit is contained in:
parent
28254e76c2
commit
96221ea4d3
@ -322,7 +322,9 @@ class Validator
|
||||
*/
|
||||
protected function validateMin($field, $value, $params)
|
||||
{
|
||||
if (function_exists('bccomp')) {
|
||||
if (!is_numeric($value)) {
|
||||
return false;
|
||||
} elseif (function_exists('bccomp')) {
|
||||
return !(bccomp($params[0], $value, 14) == 1);
|
||||
} else {
|
||||
return $params[0] <= $value;
|
||||
@ -340,7 +342,9 @@ class Validator
|
||||
*/
|
||||
protected function validateMax($field, $value, $params)
|
||||
{
|
||||
if (function_exists('bccomp')) {
|
||||
if (!is_numeric($value)) {
|
||||
return false;
|
||||
} elseif (function_exists('bccomp')) {
|
||||
return !(bccomp($value, $params[0], 14) == 1);
|
||||
} else {
|
||||
return $params[0] >= $value;
|
||||
|
||||
@ -222,6 +222,14 @@ class ValidateTest extends BaseTestCase
|
||||
$v = new Validator(array('num' => 5));
|
||||
$v->rule('min', 'num', 6);
|
||||
$this->assertFalse($v->validate());
|
||||
|
||||
$v = new Validator(array('test' => array()));
|
||||
$v->rule('min', 'test', 1);
|
||||
$this->assertFalse($v->validate());
|
||||
|
||||
$v = new Validator(array('test' => new stdClass));
|
||||
$v->rule('min', 'test', 1);
|
||||
$this->assertFalse($v->validate());
|
||||
}
|
||||
|
||||
public function testMinInvalidFloat()
|
||||
@ -262,6 +270,14 @@ class ValidateTest extends BaseTestCase
|
||||
$v = new Validator(array('num' => 5));
|
||||
$v->rule('max', 'num', 4);
|
||||
$this->assertFalse($v->validate());
|
||||
|
||||
$v = new Validator(array('test' => array()));
|
||||
$v->rule('min', 'test', 1);
|
||||
$this->assertFalse($v->validate());
|
||||
|
||||
$v = new Validator(array('test' => new stdClass));
|
||||
$v->rule('min', 'test', 1);
|
||||
$this->assertFalse($v->validate());
|
||||
}
|
||||
|
||||
public function testMaxInvalidFloat()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user