From e3b0aca95eea3359c756a6b0a3e7ee272f8d145f Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Sun, 21 Aug 2016 17:09:43 +0200 Subject: [PATCH] Removed bug fix for Helper::_confirm to keep the code compatible --- lib/Cake/Test/Case/View/Helper/FormHelperTest.php | 10 +++++----- lib/Cake/View/Helper.php | 4 ++-- lib/Cake/View/Helper/FormHelper.php | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index fab4f12ef..58a4545ab 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -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\(\"\;Confirm thing\"\;\)\) \{ document\.post_\w+\.submit\(\); \} else \{ \} event\.returnValue = false; return false;/'), + 'a' => array('class' => 'btn btn-danger', 'href' => '#', 'onclick' => 'preg:/if \(confirm\(\"\;Confirm thing\"\;\)\) \{ 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' ); diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index aadbc6c15..ef214f368 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -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); } diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 2199450c0..6896e2b76 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -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) {