Skip to content

Commit 4b269e3

Browse files
committed
Fixing RequestHandler::beforeRedirect() and issues with array urls, where incompatibilities between standard url arrays and requestAction url arrays caused incorrect results. Tests added. Fixes #276
1 parent 7daad4a commit 4b269e3

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

cake/libs/controller/components/request_handler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ function beforeRedirect(&$controller, $url) {
230230
foreach ($_POST as $key => $val) {
231231
unset($_POST[$key]);
232232
}
233+
if (is_array($url)) {
234+
$url = Router::url($url + array('base' => false));
235+
}
233236
echo $this->requestAction($url, array('return'));
234237
$this->_stop();
235238
}

cake/tests/cases/libs/controller/components/request_handler.test.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ function destination() {
7070
$this->viewPath = 'posts';
7171
$this->render('index');
7272
}
73+
/**
74+
* test method for ajax redirection + parameter parsing
75+
*
76+
* @return void
77+
*/
78+
function param_method($one = null, $two = null) {
79+
echo "one: $one two: $two";
80+
$this->autoRender = false;
81+
}
7382
}
7483
/**
7584
* RequestHandlerTestDisabledController class
@@ -541,5 +550,35 @@ function testAjaxRedirectAsRequestAction() {
541550
Configure::write('viewPaths', $_paths);
542551
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
543552
}
553+
554+
/**
555+
* test that the beforeRedirect callback properly converts
556+
* array urls into their correct string ones, and adds base => false so
557+
* the correct urls are generated.
558+
*
559+
* @link http://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/276
560+
* @return void
561+
*/
562+
function testBeforeRedirectCallbackWithArrayUrl() {
563+
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
564+
App::build(array(
565+
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
566+
), true);
567+
Router::setRequestInfo(array(
568+
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/'), 'bare' => 0),
569+
array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
570+
));
571+
572+
$RequestHandler =& new NoStopRequestHandler();
573+
574+
ob_start();
575+
$RequestHandler->beforeRedirect(
576+
$this->Controller,
577+
array('controller' => 'request_handler_test', 'action' => 'param_method', 'first', 'second')
578+
);
579+
$result = ob_get_clean();
580+
$this->assertEqual($result, 'one: first two: second');
581+
App::build();
582+
}
544583
}
545584
?>

0 commit comments

Comments
 (0)