Skip to content

Commit

Permalink
refs #8654 FormHelper cleanup unlockFields key
Browse files Browse the repository at this point in the history
  • Loading branch information
nojimage authored and markstory committed Jun 29, 2016
1 parent f28c21c commit 57e0a97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -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
*
Expand Down
4 changes: 4 additions & 0 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -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) {
Expand Down

0 comments on commit 57e0a97

Please sign in to comment.