Skip to content

Commit

Permalink
Fix Token fields being added to GET forms.
Browse files Browse the repository at this point in the history
They are not used so there is not much point in appending them.

Fixes #3565
  • Loading branch information
markstory committed Jan 25, 2013
1 parent e4f241d commit ce7f85a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -723,6 +723,23 @@ public function testCreateWithSecurity() {
$this->assertTags($result, $expected);
}

/**
* testFormCreateGetNoSecurity method
*
* Test form->create() with no security key as its a get form
*
* @return void
*/
public function testCreateEndGetNoSecurity() {
$this->Form->request['_Token'] = array('key' => 'testKey');
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact', array('type' => 'get', 'url' => '/contacts/add'));
$this->assertNotContains('Token', $result);

$result = $this->Form->end('Save');
$this->assertNotContains('Token', $result);
}

/**
* test that create() clears the fields property so it starts fresh
*
Expand Down
10 changes: 8 additions & 2 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -433,7 +433,9 @@ public function create($model = null, $options = array()) {
$htmlAttributes = array_merge($options, $htmlAttributes);

$this->fields = array();
$append .= $this->_csrfField();
if ($this->requestType !== 'get') {
$append .= $this->_csrfField();
}

if (!empty($append)) {
$append = $this->Html->useTag('block', ' style="display:none;"', $append);
Expand Down Expand Up @@ -504,7 +506,11 @@ public function end($options = null) {
}
$out .= $this->submit($submit, $submitOptions);
}
if (isset($this->request['_Token']) && !empty($this->request['_Token'])) {
if (
$this->requestType !== 'get' &&
isset($this->request['_Token']) &&
!empty($this->request['_Token'])
) {
$out .= $this->secure($this->fields);
$this->fields = array();
}
Expand Down

0 comments on commit ce7f85a

Please sign in to comment.