mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Fixing safe parameter from leaking into request() calls in JsHelper::submit() and JsHelper::link(). Fixes #656
This commit is contained in:
parent
1180f66cc0
commit
c48f6d6536
2 changed files with 28 additions and 14 deletions
|
@ -309,17 +309,22 @@ class JsHelper extends AppHelper {
|
||||||
list($options, $htmlOptions) = $this->_getHtmlOptions($options);
|
list($options, $htmlOptions) = $this->_getHtmlOptions($options);
|
||||||
$out = $this->Html->link($title, $url, $htmlOptions);
|
$out = $this->Html->link($title, $url, $htmlOptions);
|
||||||
$this->get('#' . $htmlOptions['id']);
|
$this->get('#' . $htmlOptions['id']);
|
||||||
$requestString = '';
|
$requestString = $event = '';
|
||||||
if (isset($options['confirm'])) {
|
if (isset($options['confirm'])) {
|
||||||
$requestString = $this->confirmReturn($options['confirm']);
|
$requestString = $this->confirmReturn($options['confirm']);
|
||||||
unset($options['confirm']);
|
unset($options['confirm']);
|
||||||
}
|
}
|
||||||
|
$buffer = isset($options['buffer']) ? $options['buffer'] : null;
|
||||||
|
$safe = isset($options['safe']) ? $options['safe'] : true;
|
||||||
|
unset($options['buffer'], $options['safe']);
|
||||||
|
|
||||||
$requestString .= $this->request($url, $options);
|
$requestString .= $this->request($url, $options);
|
||||||
|
|
||||||
if (!empty($requestString)) {
|
if (!empty($requestString)) {
|
||||||
$event = $this->event('click', $requestString, $options);
|
$event = $this->event('click', $requestString, $options + array('buffer' => $buffer));
|
||||||
}
|
}
|
||||||
if (isset($options['buffer']) && $options['buffer'] == false) {
|
if (isset($buffer) && !$buffer) {
|
||||||
$opts = array_intersect_key(array('safe' => null), $options);
|
$opts = array('safe' => $safe);
|
||||||
$out .= $this->Html->scriptBlock($event, $opts);
|
$out .= $this->Html->scriptBlock($event, $opts);
|
||||||
}
|
}
|
||||||
return $out;
|
return $out;
|
||||||
|
@ -389,12 +394,17 @@ class JsHelper extends AppHelper {
|
||||||
$options['method'] = 'post';
|
$options['method'] = 'post';
|
||||||
}
|
}
|
||||||
$options['dataExpression'] = true;
|
$options['dataExpression'] = true;
|
||||||
|
|
||||||
|
$buffer = isset($options['buffer']) ? $options['buffer'] : null;
|
||||||
|
$safe = isset($options['safe']) ? $options['safe'] : true;
|
||||||
|
unset($options['buffer'], $options['safe']);
|
||||||
|
|
||||||
$requestString .= $this->request($url, $options);
|
$requestString .= $this->request($url, $options);
|
||||||
if (!empty($requestString)) {
|
if (!empty($requestString)) {
|
||||||
$event = $this->event('click', $requestString, $options);
|
$event = $this->event('click', $requestString, $options + array('buffer' => $buffer));
|
||||||
}
|
}
|
||||||
if (isset($options['buffer']) && $options['buffer'] == false) {
|
if (isset($buffer) && !$buffer) {
|
||||||
$opts = array_intersect_key(array('safe' => null), $options);
|
$opts = array('safe' => $safe);
|
||||||
$out .= $this->Html->scriptBlock($event, $opts);
|
$out .= $this->Html->scriptBlock($event, $opts);
|
||||||
}
|
}
|
||||||
return $out;
|
return $out;
|
||||||
|
|
|
@ -309,7 +309,7 @@ class JsHelperTestCase extends CakeTestCase {
|
||||||
'request', array('/posts/view/1', $options)
|
'request', array('/posts/view/1', $options)
|
||||||
));
|
));
|
||||||
$this->Js->TestJsEngine->expectAt(2, 'dispatchMethod', array(
|
$this->Js->TestJsEngine->expectAt(2, 'dispatchMethod', array(
|
||||||
'event', array('click', 'ajax code', $options)
|
'event', array('click', 'ajax code', $options + array('buffer' => null))
|
||||||
));
|
));
|
||||||
|
|
||||||
$result = $this->Js->link('test link', '/posts/view/1', $options);
|
$result = $this->Js->link('test link', '/posts/view/1', $options);
|
||||||
|
@ -362,7 +362,9 @@ CODE;
|
||||||
*/
|
*/
|
||||||
function testLinkWithNoBuffering() {
|
function testLinkWithNoBuffering() {
|
||||||
$this->_useMock();
|
$this->_useMock();
|
||||||
$this->Js->TestJsEngine->setReturnValue('dispatchMethod', 'ajax code', array('request', '*'));
|
$this->Js->TestJsEngine->setReturnValue('dispatchMethod', 'ajax code', array(
|
||||||
|
'request', array('/posts/view/1', array('update' => '#content'))
|
||||||
|
));
|
||||||
$this->Js->TestJsEngine->setReturnValue('dispatchMethod', '-event handler-', array('event', '*'));
|
$this->Js->TestJsEngine->setReturnValue('dispatchMethod', '-event handler-', array('event', '*'));
|
||||||
|
|
||||||
$options = array('update' => '#content', 'buffer' => false);
|
$options = array('update' => '#content', 'buffer' => false);
|
||||||
|
@ -411,7 +413,7 @@ CODE;
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'update' => $options['update'], 'data' => 'serialize-code',
|
'update' => $options['update'], 'data' => 'serialize-code',
|
||||||
'method' => 'post', 'dataExpression' => true
|
'method' => 'post', 'dataExpression' => true, 'buffer' => null
|
||||||
);
|
);
|
||||||
$this->Js->TestJsEngine->expectAt(3, 'dispatchMethod', array(
|
$this->Js->TestJsEngine->expectAt(3, 'dispatchMethod', array(
|
||||||
'event', array('click', "ajax-code", $params)
|
'event', array('click', "ajax-code", $params)
|
||||||
|
@ -440,7 +442,7 @@ CODE;
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'update' => '#content', 'data' => 'serialize-code',
|
'update' => '#content', 'data' => 'serialize-code',
|
||||||
'method' => 'post', 'dataExpression' => true
|
'method' => 'post', 'dataExpression' => true, 'buffer' => null
|
||||||
);
|
);
|
||||||
$this->Js->TestJsEngine->expectAt(7, 'dispatchMethod', array(
|
$this->Js->TestJsEngine->expectAt(7, 'dispatchMethod', array(
|
||||||
'event', array('click', "ajax-code", $params)
|
'event', array('click', "ajax-code", $params)
|
||||||
|
@ -471,11 +473,13 @@ CODE;
|
||||||
|
|
||||||
$this->Js->TestJsEngine->expectAt(0, 'dispatchMethod', array('get', '*'));
|
$this->Js->TestJsEngine->expectAt(0, 'dispatchMethod', array('get', '*'));
|
||||||
$this->Js->TestJsEngine->expectAt(1, 'dispatchMethod', array(new PatternExpectation('/serializeForm/i'), '*'));
|
$this->Js->TestJsEngine->expectAt(1, 'dispatchMethod', array(new PatternExpectation('/serializeForm/i'), '*'));
|
||||||
$this->Js->TestJsEngine->expectAt(2, 'dispatchMethod', array('request', '*'));
|
$this->Js->TestJsEngine->expectAt(2, 'dispatchMethod', array('request', array(
|
||||||
|
'', array('update' => $options['update'], 'data' => 'serialize-code', 'method' => 'post', 'dataExpression' => true)
|
||||||
|
)));
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'update' => $options['update'], 'buffer' => false, 'safe' => false, 'data' => 'serialize-code',
|
'update' => $options['update'], 'data' => 'serialize-code',
|
||||||
'method' => 'post', 'dataExpression' => true
|
'method' => 'post', 'dataExpression' => true, 'buffer' => false
|
||||||
);
|
);
|
||||||
$this->Js->TestJsEngine->expectAt(3, 'dispatchMethod', array(
|
$this->Js->TestJsEngine->expectAt(3, 'dispatchMethod', array(
|
||||||
'event', array('click', "ajax-code", $params)
|
'event', array('click', "ajax-code", $params)
|
||||||
|
|
Loading…
Add table
Reference in a new issue