From 50144d6b5b1db2d31e1be3019e47c66a58fc50f3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 12 Jun 2010 22:50:09 -0400 Subject: [PATCH] Making FormHelper clear fields on create() as well as end() this ensures that GET forms don't leak fields. Fixes #571 --- cake/libs/view/helpers/form.php | 1 + cake/tests/cases/libs/view/helpers/form.test.php | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 3de99f084..4e1a209b3 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -306,6 +306,7 @@ class FormHelper extends AppHelper { 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()) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 7678020db..c17c2c69a 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -751,6 +751,17 @@ class FormHelperTest extends CakeTestCase { $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 *