From c729a0c4acb1fe9ee4aba6b0015d5d64d54a40f7 Mon Sep 17 00:00:00 2001 From: Elizabeth M Smith Date: Fri, 23 Jun 2017 13:41:39 -0400 Subject: [PATCH 1/3] avoids php blowing up if an array value is passed if incoming data has an array value set with a slug rule on it, you get preg_match() expects parameter 2 to be string, array given vendor\vlucas\valitron\src\Valitron\Validator.php:571 --- src/Valitron/Validator.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index 5fc5c84..f6bd446 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -565,6 +565,9 @@ class Validator */ protected function validateSlug($field, $value) { + if(is_array($value)) { + return false; + } return preg_match('/^([-a-z0-9_-])+$/i', $value); } From 05b5c40515c9848838dd6be3ce30109542680f5a Mon Sep 17 00:00:00 2001 From: Elizabeth M Smith Date: Fri, 23 Jun 2017 13:43:15 -0400 Subject: [PATCH 2/3] test for the change --- tests/Valitron/ValidateTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index 490424e..00283a4 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -616,6 +616,13 @@ class ValidateTest extends BaseTestCase $v->rule('slug', 'test'); $this->assertFalse($v->validate()); } + + public function testNoErrorFailOnArray() + { + $v = new Validator(array('test' => [])); + $v->rule('slug', 'test'); + $this->assertFalse($v->validate()); + } public function testRegexValid() { From 4896ade38729f5cf2fd4a561954ab2ad51c20893 Mon Sep 17 00:00:00 2001 From: Elizabeth M Smith Date: Fri, 23 Jun 2017 13:50:49 -0400 Subject: [PATCH 3/3] really? 5.3 support? ewww --- tests/Valitron/ValidateTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index 00283a4..0bd0754 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -619,7 +619,7 @@ class ValidateTest extends BaseTestCase public function testNoErrorFailOnArray() { - $v = new Validator(array('test' => [])); + $v = new Validator(array('test' => array())); $v->rule('slug', 'test'); $this->assertFalse($v->validate()); }