From 1f0c9736819b8bb879641bb6cbaaf5ddc826c7e4 Mon Sep 17 00:00:00 2001 From: Wouter Date: Fri, 9 Mar 2018 16:51:08 +0100 Subject: [PATCH 1/2] Don't break on removing a non-existing rule --- lib/Cake/Model/ModelValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/ModelValidator.php b/lib/Cake/Model/ModelValidator.php index f968e2cff..c84e58f75 100644 --- a/lib/Cake/Model/ModelValidator.php +++ b/lib/Cake/Model/ModelValidator.php @@ -594,7 +594,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable { $this->_parseRules(); if ($rule === null) { unset($this->_fields[$field]); - } else { + } elseif (array_key_exists($field, $this->_fields)) { $this->_fields[$field]->removeRule($rule); } return $this; From b225443166534f0528f59a071083034b10556e1a Mon Sep 17 00:00:00 2001 From: Wouter Date: Wed, 14 Mar 2018 11:32:58 +0100 Subject: [PATCH 2/2] Test removing a rule on a previously removed field --- lib/Cake/Test/Case/Model/ModelValidationTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Cake/Test/Case/Model/ModelValidationTest.php b/lib/Cake/Test/Case/Model/ModelValidationTest.php index e1984b219..7886fdd75 100644 --- a/lib/Cake/Test/Case/Model/ModelValidationTest.php +++ b/lib/Cake/Test/Case/Model/ModelValidationTest.php @@ -2007,6 +2007,9 @@ class ModelValidationTest extends BaseModelTest { $this->assertTrue(isset($Validator['other'])); $this->assertFalse(isset($Validator['other']['numeric'])); $this->assertTrue(isset($Validator['other']['between'])); + + $Validator->remove('other'); + $Validator->remove('other', 'between'); } /**