Adding FormHelper security token patch from renan.saddam, fixes #5061, adding test to disprove #2729 (FormHelper::input() and float fields)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7486 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-08-22 16:05:34 +00:00
parent dbbbccdf18
commit 6f660812ca
2 changed files with 51 additions and 15 deletions

View file

@ -972,6 +972,10 @@ class FormHelper extends AppHelper {
if (!in_array($fieldName, array('_method'))) {
$this->__secure($key, $value);
if (!in_array($model, array('_Token', '__Token')) && $value === '0') {
$this->__secure($model);
}
}
return $this->output(sprintf($this->Html->tags['hidden'], $options['name'], $this->_parseAttributes($options, array('name', 'class'), '', ' ')));
}

View file

@ -82,6 +82,22 @@ class Contact extends CakeTestModel {
* @access public
*/
var $name = 'Contact';
/**
* Default schema
*
* @var array
* @access public
*/
var $_schema = array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'phone' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'password' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
/**
* validate property
*
@ -102,18 +118,8 @@ class Contact extends CakeTestModel {
* @access public
* @return void
*/
function schema() {
$this->_schema = array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'phone' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'password' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
return $this->_schema;
function setSchema($schema) {
$this->_schema = $schema;
}
/**
* hasAndBelongsToMany property
@ -616,6 +622,32 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
}
/**
* Tests correct generation of text fields for double and float fields
*
* @access public
* @return void
*/
function testTextFieldGenerationForFloats() {
$model = ClassRegistry::getObject('Contact');
$model->setSchema(array('foo' => array(
'type' => 'float',
'null' => false,
'default' => null,
'length' => null
)));
$this->Form->create('Contact');
$result = $this->Form->input('foo');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactFoo'),
'Foo',
'/label',
array('input' => array('type' => 'text', 'name' => 'data[Contact][foo]', 'value' => '', 'id' => 'ContactFoo')),
'/div'
);
}
/**
* testFormSecurityMultipleFields method
*