mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
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
This commit is contained in:
parent
9147f545fe
commit
e23c4ffad9
2 changed files with 20 additions and 0 deletions
|
@ -244,6 +244,9 @@ class RequestHandlerComponent extends Component {
|
||||||
if (!$this->request->is('ajax')) {
|
if (!$this->request->is('ajax')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (empty($url)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||||
foreach ($_POST as $key => $val) {
|
foreach ($_POST as $key => $val) {
|
||||||
unset($_POST[$key]);
|
unset($_POST[$key]);
|
||||||
|
|
|
@ -411,6 +411,23 @@ class RequestHandlerComponentTest extends CakeTestCase {
|
||||||
$this->assertNull($this->RequestHandler->beforeRedirect($this->Controller, '/'));
|
$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
|
* testRenderAs method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue