Removed bug fix for Helper::_confirm to keep the code compatible

This commit is contained in:
Mark van Driel 2016-08-21 17:09:43 +02:00
parent 34afc377ec
commit e3b0aca95e
3 changed files with 11 additions and 10 deletions

View file

@ -8095,7 +8095,7 @@ class FormHelperTest extends CakeTestCase {
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form',
'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\("Confirm\?"\)\) \{ document\.post_\w+\.submit\(\); \} else \{ \} event\.returnValue = false; return false;/'),
'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\("Confirm\?"\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
'Delete',
'/a'
));
@ -8108,7 +8108,7 @@ class FormHelperTest extends CakeTestCase {
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form',
'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\("'Confirm' this \\\\"deletion\\\\"\?"\)\) \{ document\.post_\w+\.submit\(\); \} else \{ \} event\.returnValue = false; return false;/'),
'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\("'Confirm' this \\\\"deletion\\\\"\?"\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
'Delete',
'/a'
));
@ -8142,7 +8142,7 @@ class FormHelperTest extends CakeTestCase {
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form',
'a' => array('class' => 'btn btn-danger', 'href' => '#', 'onclick' => 'preg:/if \(confirm\(\&quot\;Confirm thing\&quot\;\)\) \{ document\.post_\w+\.submit\(\); \} else \{ \} event\.returnValue = false; return false;/'),
'a' => array('class' => 'btn btn-danger', 'href' => '#', 'onclick' => 'preg:/if \(confirm\(\&quot\;Confirm thing\&quot\;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
'/a'
));
}
@ -8454,7 +8454,7 @@ class FormHelperTest extends CakeTestCase {
'div' => array('class' => 'submit'),
'input' => array(
'type' => 'submit', 'value' => 'Test',
'onclick' => 'preg:/if \(confirm\("Confirm\?"\)\) \{ \} else \{ event\.returnValue = false; return false; \}/'
'onclick' => 'preg:/if \(confirm\("Confirm\?"\)\) \{ return true; \} event\.returnValue = false; return false;/'
),
'/div'
);
@ -8544,7 +8544,7 @@ class FormHelperTest extends CakeTestCase {
'div' => array('class' => 'submit'),
'input' => array(
'type' => 'image', 'src' => 'img/cake.power.gif',
'onclick' => 'preg:/if \(confirm\("Confirm\?"\)\) \{ \} else \{ event\.returnValue = false; return false; \}/'
'onclick' => 'preg:/if \(confirm\("Confirm\?"\)\) \{ return true; \} event\.returnValue = false; return false;/'
),
'/div'
);

View file

@ -546,13 +546,13 @@ class Helper extends Object {
*
* @param string $message Message to be displayed
* @param string $okCode Code to be executed after user chose 'OK'
* @param string $cancelCode Code to be executed after user chose 'Cancel'
* @param string $cancelCode Code to be executed after user chose 'Cancel', also executed when okCode doesn't return
* @param array $options Array of options
* @return string onclick JS code
*/
protected function _confirm($message, $okCode, $cancelCode = '', $options = array()) {
$message = json_encode($message);
$confirm = "if (confirm({$message})) { {$okCode} } else { {$cancelCode} }";
$confirm = "if (confirm({$message})) { {$okCode} } {$cancelCode}";
if (isset($options['escape']) && $options['escape'] === false) {
$confirm = h($confirm);
}

View file

@ -1920,9 +1920,9 @@ class FormHelper extends AppHelper {
if ($confirmMessage) {
$options['onclick'] = $this->_confirm($confirmMessage, $onClick, '', $options);
} else {
$options['onclick'] = $onClick;
$options['onclick'] = $onClick . ' ';
}
$options['onclick'] .= ' event.returnValue = false; return false;';
$options['onclick'] .= 'event.returnValue = false; return false;';
$out .= $this->Html->link($title, $url, $options);
return $out;
@ -2012,8 +2012,9 @@ class FormHelper extends AppHelper {
}
if ($confirmMessage) {
$okCode = 'return true;';
$cancelCode = 'event.returnValue = false; return false;';
$options['onclick'] = $this->_confirm($confirmMessage, '', $cancelCode, $options);
$options['onclick'] = $this->_confirm($confirmMessage, $okCode, $cancelCode, $options);
}
if ($isUrl) {