mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Fix FormHelper::postLink() not working when SecurityComponent is enabled.
The action attribute value was not being included in the generated hash, so postLink() forms never worked properly. Fixes #3418
This commit is contained in:
parent
1a39917e76
commit
e1057e3e6b
2 changed files with 36 additions and 0 deletions
|
@ -7616,6 +7616,40 @@ class FormHelperTest extends CakeTestCase {
|
|||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that security hashes for postLink include the url.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPostLinkSecurityHash() {
|
||||
$hash = Security::hash(
|
||||
'/posts/delete/1' .
|
||||
serialize(array()) .
|
||||
'' .
|
||||
Configure::read('Security.salt')
|
||||
);
|
||||
$hash .= '%3A';
|
||||
$this->Form->request->params['_Token']['key'] = 'test';
|
||||
|
||||
$result = $this->Form->postLink('Delete', '/posts/delete/1');
|
||||
$this->assertTags($result, array(
|
||||
'form' => array(
|
||||
'method' => 'post', 'action' => '/posts/delete/1',
|
||||
'name', 'id', 'style' => 'display:none;'
|
||||
),
|
||||
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
||||
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'test', 'id')),
|
||||
'div' => array('style' => 'display:none;'),
|
||||
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => $hash, 'id')),
|
||||
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id')),
|
||||
'/div',
|
||||
'/form',
|
||||
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
||||
'Delete',
|
||||
'/a'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test using postLink with N dimensional data.
|
||||
*
|
||||
|
|
|
@ -1790,6 +1790,8 @@ class FormHelper extends AppHelper {
|
|||
unset($options['target']);
|
||||
}
|
||||
|
||||
$this->_lastAction = $formUrl;
|
||||
|
||||
$out = $this->Html->useTag('form', $formUrl, $formOptions);
|
||||
$out .= $this->Html->useTag('hidden', '_method', array(
|
||||
'value' => $requestMethod
|
||||
|
|
Loading…
Add table
Reference in a new issue