diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index f72ea120d26..6ca879919db 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -1619,6 +1619,29 @@ public function testResetUnlockFields() { $this->assertEquals(1, $this->Form->fields['Contact.id'], 'Hidden input should be secured.'); } +/** + * test unlockField removing from fields array. multiple field version. + * + * @return void + */ + public function testUnlockMultipleFieldRemovingFromFields() { + $this->Form->request['_Token'] = array( + 'key' => 'testKey', + 'unlockedFields' => array() + ); + $this->Form->create('Order'); + $this->Form->hidden('Order.id', array('value' => 1)); + $this->Form->checkbox('Ticked.id.'); + $this->Form->checkbox('Ticked.id.'); + + $this->assertEquals(1, $this->Form->fields['Order.id'], 'Hidden input should be secured.'); + $this->assertTrue(in_array('Ticked.id', $this->Form->fields), 'Field should be secured.'); + + $this->Form->unlockField('Order.id'); + $this->Form->unlockField('Ticked.id'); + $this->assertEquals(array(), $this->Form->fields); + } + /** * testTagIsInvalid method * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index f52b74dedc5..e4cbfda9c31 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -666,6 +666,10 @@ protected function _secure($lock, $field = null, $value = null) { $field = Hash::filter(explode('.', $field)); } + if (is_array($field)) { + $field = array_filter($field, 'strlen'); + } + foreach ($this->_unlockedFields as $unlockField) { $unlockParts = explode('.', $unlockField); if (array_values(array_intersect($field, $unlockParts)) === $unlockParts) {