Fixing issue where radio elements would produce wrong hash when Security component enabled in FormHelper, fixes #5791

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7891 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2008-11-25 16:32:54 +00:00
parent acaaa7ee64
commit f9557c7611
3 changed files with 61 additions and 6 deletions

View file

@ -344,10 +344,13 @@ class FormHelper extends AppHelper {
}
}
}
if ($value !== null) {
return $this->fields[join('.', $field)] = $value;
$field = join('.', $field);
if (!in_array($field, $this->fields)) {
if ($value !== null) {
return $this->fields[$field] = $value;
}
$this->fields[] = $field;
}
$this->fields[] = join('.', $field);
}
/**
* Returns true if there is an error for the given field, otherwise false

View file

@ -33,7 +33,6 @@ App::import('Component', 'Security');
* @subpackage cake.tests.cases.libs.controller.components
*/
class TestSecurityComponent extends SecurityComponent {
function validatePost(&$controller) {
return $this->_validatePost($controller);
}
@ -1006,6 +1005,44 @@ DIGEST;
$this->assertTrue($result);
}
/**
* testRadio method
*
* @access public
* @return void
*/
function testRadio() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->params['_Token']['key'];
$fields = '575ef54ca4fc8cab468d6d898e9acd3a9671c17e%3An%3A0%3A%7B%7D';
$this->Controller->data = array(
'_Token' => compact('key', 'fields')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertFalse($result);
$this->Controller->data = array(
'_Token' => compact('key', 'fields'),
'Test' => array('test' => '')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
$this->Controller->data = array(
'_Token' => compact('key', 'fields'),
'Test' => array('test' => '1')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
$this->Controller->data = array(
'_Token' => compact('key', 'fields'),
'Test' => array('test' => '2')
);
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
}
/**
* testInvalidAuthHeaders method
*
* @access public
@ -1026,4 +1063,4 @@ DIGEST;
}
}
?>
?>

View file

@ -1058,6 +1058,21 @@ class FormHelperTest extends CakeTestCase {
$this->Form->select('Model.select', $options, null, array('multiple' => true));
$this->assertEqual($this->Form->fields, $expected);
}
/**
* testFormSecuredRadio method
*
* @access public
* @return void
*/
function testFormSecuredRadio() {
$this->Form->params['_Token']['key'] = 'testKey';
$this->assertEqual($this->Form->fields, array());
$options = array('1' => 'option1', '2' => 'option2');
$this->Form->radio('Test.test', $options);
$expected = array('Test.test');
$this->assertEqual($this->Form->fields, $expected);
}
/**
* testPasswordValidation method
*
@ -3188,7 +3203,7 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$selected = '1225031586';
$selected = strtotime('2008-10-26 10:33:00');
$result = $this->Form->dateTime('Model.field', 'DMY', '12', $selected);
$this->assertPattern('/<option[^<>]+value="2008"[^<>]+selected="selected"[^>]*>2008<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>10<\/option>/', $result);