Skip to content

Commit 5446a06

Browse files
committed
Fixing issue where whitelist would not be used for validation. Test case added. Fixes #1037
1 parent 12d4b52 commit 5446a06

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

cake/libs/model/model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2511,7 +2511,7 @@ function invalidFields($options = array()) {
25112511
$_validate = $this->validate;
25122512
$whitelist = $this->whitelist;
25132513

2514-
if (array_key_exists('fieldList', $options)) {
2514+
if (!empty($options['fieldList'])) {
25152515
$whitelist = $options['fieldList'];
25162516
}
25172517

cake/tests/cases/libs/model/model_validation.test.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,34 @@ function testInvalidFieldsWithFieldListParams() {
164164
$TestModel->invalidFields();
165165
$expected = array('name' => 'This field cannot be left blank');
166166
$this->assertEqual($TestModel->validationErrors, $expected);
167-
$TestModel->validationErrors = array();
168167

169168
$this->assertEqual($TestModel->validate, $validate);
170169
}
171170

171+
/**
172+
* Test that invalidFields() integrates well with save(). And that fieldList can be an empty type.
173+
*
174+
* @return void
175+
*/
176+
function testInvalidFieldsWhitelist() {
177+
$TestModel =& new ValidationTest1();
178+
$TestModel->validate = $validate = array(
179+
'title' => array(
180+
'rule' => 'customValidator',
181+
'required' => true
182+
),
183+
'name' => array(
184+
'rule' => 'alphaNumeric',
185+
'required' => true
186+
));
187+
188+
$TestModel->whitelist = array('name');
189+
$TestModel->save(array('name' => '#$$#'));
190+
191+
$expected = array('name' => 'This field cannot be left blank');
192+
$this->assertEqual($TestModel->validationErrors, $expected);
193+
}
194+
172195
/**
173196
* testValidates method
174197
*

0 commit comments

Comments
 (0)