mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Add some validation to prevent PHP Warning when value in subset validation is null
This commit is contained in:
parent
a8346868c2
commit
21e9dc1263
@ -489,7 +489,7 @@ class Validator
|
||||
if (!is_array($params[0])) {
|
||||
$params[0] = array($params[0]);
|
||||
}
|
||||
if (is_scalar($value)) {
|
||||
if (is_scalar($value) || is_null($value)) {
|
||||
return $this->validateIn($field, $value, $params);
|
||||
}
|
||||
|
||||
|
||||
@ -1720,6 +1720,15 @@ class ValidateTest extends BaseTestCase
|
||||
$this->assertFalse($v->validate());
|
||||
}
|
||||
|
||||
public function testSubsetAcceptNullValue()
|
||||
{
|
||||
// rule value equals null
|
||||
$v = new Validator(array('test_field' => null));
|
||||
$v->rule('required', 'test_field');
|
||||
$v->rule('subset', 'test_field', array('black', 45));
|
||||
$this->assertFalse($v->validate());
|
||||
}
|
||||
|
||||
public function testContainsUniqueValid()
|
||||
{
|
||||
// numeric values
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user