Skip to content

Commit

Permalink
Removing extra 0 index in request parameters.
Browse files Browse the repository at this point in the history
When using requestAction with the return parameter, there
would be an extra 0 index element that would create incorrect
routes in the requestedAction.
Fixes #2067
  • Loading branch information
markstory committed Oct 6, 2011
1 parent 2cc9523 commit ea11392
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
6 changes: 4 additions & 2 deletions lib/Cake/Core/Object.php
Expand Up @@ -65,8 +65,10 @@ public function requestAction($url, $extra = array()) {
return false;
}
App::uses('Dispatcher', 'Routing');
if (in_array('return', $extra, true)) {
$extra = array_merge($extra, array('return' => 0, 'autoRender' => 1));
if (($index = array_search('return', $extra)) !== false) {
$extra['return'] = 0;
$extra['autoRender'] = 1;
unset($extra[$index]);
}
if (is_array($url) && !isset($extra['url'])) {
$extra['url'] = array();
Expand Down
32 changes: 22 additions & 10 deletions lib/Cake/Test/Case/Core/ObjectTest.php
Expand Up @@ -124,7 +124,16 @@ public function post_pass() {
* @return array
*/
public function params_pass() {
return $this->params;
return $this->request;
}

public function param_check() {
$this->autoRender = false;
$content = '';
if (isset($this->request->params[0])) {
$content = 'return found';
}
$this->response->body($content);
}
}

Expand Down Expand Up @@ -564,6 +573,18 @@ public function testRequestActionArray() {
$this->assertTrue($result);
}

/**
* Test that requestAction() does not forward the 0 => return value.
*
* @return void
*/
public function testRequestActionRemoveReturnParam() {
$result = $this->object->requestAction(
'/request_action/param_check', array('return')
);
$this->assertEquals('', $result, 'Return key was found');
}

/**
* Test that requestAction() is populating $this->params properly
*
Expand Down Expand Up @@ -615,13 +636,4 @@ public function testRequestActionPostPassing() {

$_POST = $_tmp;
}

/**
* testCakeError
*
* @return void
*/
public function testCakeError() {

}
}

0 comments on commit ea11392

Please sign in to comment.