From 0bda6ee4028ca3154628dea0b3ef52de493a3eaa Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Fri, 22 Sep 2017 23:26:44 -0500 Subject: [PATCH] REturn false from validation when no rules exist --- system/Validation/Validation.php | 7 +++++++ tests/system/Validation/ValidationTest.php | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index 412e81e32002..934ae3b39ff1 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -129,6 +129,13 @@ public function run(array $data = null, string $group = null): bool $this->loadRuleGroup($group); + // If no rules exist, we return false to ensure + // the developer didn't forget to set the rules. + if (empty($this->rules)) + { + return false; + } + // Run through each rule. If we have any field set for // this rule, then we need to run them through! foreach ($this->rules as $rField => $ruleString) diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php index 66a34305e4fe..dfc47016b3a4 100644 --- a/tests/system/Validation/ValidationTest.php +++ b/tests/system/Validation/ValidationTest.php @@ -55,11 +55,11 @@ public function testSetRulesStoresRules() //-------------------------------------------------------------------- - public function testRunReturnsTrueWithNothingToDo() + public function testRunReturnsFalseWithNothingToDo() { $this->validation->setRules([]); - $this->assertTrue($this->validation->run([])); + $this->assertFalse($this->validation->run([])); } //--------------------------------------------------------------------