Skip to content

Commit

Permalink
Fix radio buttons not being added to security hash.
Browse files Browse the repository at this point in the history
When some but not all inputs were disabled radio buttons were omitted
from the security hash. This caused blackhole failures as the input was
unexpected.

Refs #5603
  • Loading branch information
markstory committed Jan 9, 2015
1 parent 642e11e commit 98909fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
16 changes: 15 additions & 1 deletion lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -1338,6 +1338,18 @@ public function testSecuredRadio() {
$this->Form->radio('Test.test', $options);
$expected = array('Test.test');
$this->assertEquals($expected, $this->Form->fields);

$this->Form->radio('Test.all', $options, array(
'disabled' => array('option1', 'option2')
));
$expected = array('Test.test', 'Test.all' => '');
$this->assertEquals($expected, $this->Form->fields);

$this->Form->radio('Test.some', $options, array(
'disabled' => array('option1')
));
$expected = array('Test.test', 'Test.all' => '', 'Test.some');
$this->assertEquals($expected, $this->Form->fields);
}

/**
Expand Down Expand Up @@ -1372,9 +1384,11 @@ public function testSecuredAndDisabled() {

$this->Form->checkbox('Model.checkbox', array('disabled' => true));
$this->Form->text('Model.text', array('disabled' => true));
$this->Form->password('Model.text', array('disabled' => true));
$this->Form->text('Model.text2', array('disabled' => 'disabled'));
$this->Form->password('Model.password', array('disabled' => true));
$this->Form->textarea('Model.textarea', array('disabled' => true));
$this->Form->select('Model.select', array(1, 2), array('disabled' => true));
$this->Form->select('Model.select', array(1, 2), array('disabled' => array(1, 2)));
$this->Form->radio('Model.radio', array(1, 2), array('disabled' => array(1, 2)));
$this->Form->year('Model.year', null, null, array('disabled' => true));
$this->Form->month('Model.month', array('disabled' => true));
Expand Down
15 changes: 14 additions & 1 deletion lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -1491,7 +1491,9 @@ public function checkbox($fieldName, $options = array()) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs
*/
public function radio($fieldName, $options = array(), $attributes = array()) {
$attributes['options'] = $options;
$attributes = $this->_initInputField($fieldName, $attributes);
unset($attributes['options']);

$showEmpty = $this->_extractOption('empty', $attributes);
if ($showEmpty) {
Expand Down Expand Up @@ -2955,7 +2957,18 @@ protected function _initInputField($field, $options = array()) {
$result = $this->addClass($result, 'form-error');
}

if (!empty($result['disabled'])) {
$isDisabled = false;
if (isset($result['disabled'])) {
$isDisabled = (
$result['disabled'] === true ||
$result['disabled'] === 'disabled' ||
(is_array($result['disabled']) &&
!empty($result['options']) &&
array_diff($result['options'], $result['disabled']) === array()
)
);
}
if ($isDisabled) {
return $result;
}

Expand Down

0 comments on commit 98909fb

Please sign in to comment.