Skip to content
Permalink
Browse files

Fix use of data()

Fix a type error in getData() when request->data is invalid.
  • Loading branch information...
markstory committed Feb 3, 2017
1 parent 46fc1d1 commit dec61b9d017e58132012227367a8e8a063d7cd4e
@@ -265,7 +265,7 @@ protected function _authRequired(Controller $controller)
$requireAuth = $this->_config['requireAuth'];
if (in_array($request->getParam('action'), $requireAuth) || $requireAuth == ['*']) {
if (!isset($request->data['_Token'])) {
if ($request->getData('_Token') === null) {
throw new AuthSecurityException('\'_Token\' was not found in request data.');
}
@@ -1489,6 +1489,9 @@ public function getData($name = null, $default = null)
if ($name === null) {
return $this->data;
}
if (!is_array($this->data) && $name) {
return $default;
}
return Hash::get($this->data, $name, $default);
}
@@ -2520,7 +2520,7 @@ public function testReadingParams()
*
* @return void
*/
public function testDataReading()
public function testGetData()
{
$post = [
'Model' => [
@@ -2541,6 +2541,19 @@ public function testDataReading()
$this->assertSame('default', $request->getData('Model.imaginary', 'default'));
}
/**
* Test that getData() doesn't fail on scalar data.
*
* @return void
*/
public function testGetDataOnStringData()
{
$post = 'strange, but could happen';
$request = new Request(compact('post'));
$this->assertNull($request->getData('Model'));
$this->assertNull($request->getData('Model.field'));
}
/**
* Test writing with data()
*

0 comments on commit dec61b9

Please sign in to comment.
You can’t perform that action at this time.