diff --git a/lib/Cake/Controller/Component/RequestHandlerComponent.php b/lib/Cake/Controller/Component/RequestHandlerComponent.php index 85a51f338..89e50b303 100644 --- a/lib/Cake/Controller/Component/RequestHandlerComponent.php +++ b/lib/Cake/Controller/Component/RequestHandlerComponent.php @@ -244,6 +244,9 @@ class RequestHandlerComponent extends Component { if (!$this->request->is('ajax')) { return; } + if (empty($url)) { + return; + } $_SERVER['REQUEST_METHOD'] = 'GET'; foreach ($_POST as $key => $val) { unset($_POST[$key]); diff --git a/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php b/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php index 45c656048..8beb0ce75 100644 --- a/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php @@ -411,6 +411,23 @@ class RequestHandlerComponentTest extends CakeTestCase { $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 *