mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-05 11:02:40 +00:00
Fix Token fields being added to GET forms.
They are not used so there is not much point in appending them. Fixes #3565
This commit is contained in:
parent
e4f241dd23
commit
ce7f85abe8
2 changed files with 25 additions and 2 deletions
|
@ -723,6 +723,23 @@ class FormHelperTest extends CakeTestCase {
|
|||
$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
|
||||
*
|
||||
|
|
|
@ -433,7 +433,9 @@ class FormHelper extends AppHelper {
|
|||
$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);
|
||||
|
@ -504,7 +506,11 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
$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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue