Skip to content

Commit

Permalink
Making FormHelper clear fields on create() as well as end() this ensu…
Browse files Browse the repository at this point in the history
…res that GET forms don't leak fields. Fixes #571
  • Loading branch information
markstory committed Jun 13, 2010
1 parent d1651db commit 50144d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions cake/libs/view/helpers/form.php
Expand Up @@ -306,6 +306,7 @@ function create($model = null, $options = array()) {
unset($options['default']);
$htmlAttributes = array_merge($options, $htmlAttributes);

$this->fields = array();
if (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
$append .= $this->hidden('_Token.key', array(
'value' => $this->params['_Token']['key'], 'id' => 'Token' . mt_rand())
Expand Down
11 changes: 11 additions & 0 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -751,6 +751,17 @@ function testCreateWithSecurity() {
$this->assertTags($result, $expected);
}

/**
* test that create() clears the fields property so it starts fresh
*
* @return void
*/
function testCreateClearingFields() {
$this->Form->fields = array('model_id');
$this->Form->create('Contact');
$this->assertEqual($this->Form->fields, array());
}

/**
* Tests form hash generation with model-less data
*
Expand Down

0 comments on commit 50144d6

Please sign in to comment.