Merge pull request #201 from auroraeosrose/foreachbug

Check if the value in getParts is non-scalar to prevent "Invalid argument to foreach" error
This commit is contained in:
Willem Wollebrants 2017-06-23 23:38:17 +02:00 committed by GitHub
commit a6cf3a8c86
2 changed files with 12 additions and 0 deletions

View File

@ -893,6 +893,11 @@ class Validator
return array($data, false); return array($data, false);
} }
// Catches the case where the data isn't an array or object
if (is_scalar($data)) {
return array(NULL, false);
}
$identifier = array_shift($identifiers); $identifier = array_shift($identifiers);
// Glob match // Glob match

View File

@ -35,6 +35,13 @@ class ValidateTest extends BaseTestCase
$this->assertFalse($v->validate()); $this->assertFalse($v->validate());
} }
public function testRequiredSubfieldsArrayStringValue()
{
$v = new Validator(array('name' => 'bob'));
$v->rule('required', array('name.*.red'));
$this->assertFalse($v->validate());
}
public function testRequiredValid() public function testRequiredValid()
{ {
$v = new Validator(array('name' => 'Chester Tester')); $v = new Validator(array('name' => 'Chester Tester'));