Skip to content

Commit

Permalink
Fix empty response bodies when redirect URL's are empty.
Browse files Browse the repository at this point in the history
When redirecting XHR requests to an empty URL the response body should
not be overwritten.

Fixes #3835
  • Loading branch information
markstory committed May 17, 2013
1 parent 9147f54 commit e23c4ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Cake/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -244,6 +244,9 @@ public function beforeRedirect(Controller $controller, $url, $status = null, $ex
if (!$this->request->is('ajax')) {
return;
}
if (empty($url)) {
return;
}
$_SERVER['REQUEST_METHOD'] = 'GET';
foreach ($_POST as $key => $val) {
unset($_POST[$key]);
Expand Down
Expand Up @@ -411,6 +411,23 @@ public function testNonAjaxRedirect() {
$this->assertNull($this->RequestHandler->beforeRedirect($this->Controller, '/'));
}

/**
* test that redirects with ajax and no url don't do anything.
*
* @return void
*/
public function testAjaxRedirectWithNoUrl() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->Controller->response = $this->getMock('CakeResponse');

$this->Controller->response->expects($this->never())
->method('body');

$this->RequestHandler->initialize($this->Controller);
$this->RequestHandler->startup($this->Controller);
$this->assertNull($this->RequestHandler->beforeRedirect($this->Controller, null));
}

/**
* testRenderAs method
*
Expand Down

0 comments on commit e23c4ff

Please sign in to comment.