Browse Source

Fix empty response bodies when redirect URL's are empty.

When redirecting XHR requests to an empty URL the response body should
not be overwritten.

Fixes #3835
mark_story 13 years ago
parent
commit
e23c4ffad9

+ 3 - 0
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]);

+ 17 - 0
lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php

@@ -412,6 +412,23 @@ class RequestHandlerComponentTest extends CakeTestCase {
 	}
 
 /**
+ * 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
  *
  * @return void