Merge pull request #200 from auroraeosrose/patch-1

Fix issue where preg_match spews when passed an array
This commit is contained in:
Willem Wollebrants 2017-06-23 23:34:07 +02:00 committed by GitHub
commit 1d8abc73b6
2 changed files with 10 additions and 0 deletions

View File

@ -565,6 +565,9 @@ class Validator
*/ */
protected function validateSlug($field, $value) protected function validateSlug($field, $value)
{ {
if(is_array($value)) {
return false;
}
return preg_match('/^([-a-z0-9_-])+$/i', $value); return preg_match('/^([-a-z0-9_-])+$/i', $value);
} }

View File

@ -616,6 +616,13 @@ class ValidateTest extends BaseTestCase
$v->rule('slug', 'test'); $v->rule('slug', 'test');
$this->assertFalse($v->validate()); $this->assertFalse($v->validate());
} }
public function testNoErrorFailOnArray()
{
$v = new Validator(array('test' => array()));
$v->rule('slug', 'test');
$this->assertFalse($v->validate());
}
public function testRegexValid() public function testRegexValid()
{ {