Merge pull request #13539 from mvdriel/empty-post-body-for-json-will-put-null-value-in-request-data

Empty post body for json will put null value in request->data
This commit is contained in:
Mark Story 2019-08-19 22:06:47 -04:00 committed by GitHub
commit ec8022baf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -220,7 +220,7 @@ class RequestHandlerComponent extends Component {
foreach ($this->_inputTypeMap as $type => $handler) { foreach ($this->_inputTypeMap as $type => $handler) {
if ($this->requestedWith($type)) { if ($this->requestedWith($type)) {
$input = call_user_func_array(array($controller->request, 'input'), $handler); $input = (array)call_user_func_array(array($controller->request, 'input'), $handler);
$controller->request->data = $input; $controller->request->data = $input;
} }
} }

View file

@ -399,6 +399,20 @@ class RequestHandlerComponentTest extends CakeTestCase {
$this->assertFalse(is_object($this->Controller->data)); $this->assertFalse(is_object($this->Controller->data));
} }
/**
* testStartupCallbackJson method
*
* @return void
*/
public function testStartupCallbackJson() {
$_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['CONTENT_TYPE'] = 'application/json';
$this->Controller->request = $this->getMock('CakeRequest', array('_readInput'));
$this->RequestHandler->startup($this->Controller);
$this->assertTrue(is_array($this->Controller->data));
$this->assertFalse(is_object($this->Controller->data));
}
/** /**
* testStartupCallback with charset. * testStartupCallback with charset.
* *