Fix notice error when parsing input data.

Prevent error in CakeRequest from parsing input data in
PUT and DELETE requests.

Fixes #3002

Signed-off-by: mark_story <mark@mark-story.com>
This commit is contained in:
Rodrigo Moyle 2012-07-02 19:18:12 -03:00 committed by mark_story
parent e61f636bc7
commit e10f6f57a3
2 changed files with 19 additions and 3 deletions

View file

@ -175,7 +175,8 @@ class CakeRequest implements ArrayAccess {
if (env('HTTP_X_HTTP_METHOD_OVERRIDE')) {
$this->data['_method'] = env('HTTP_X_HTTP_METHOD_OVERRIDE');
}
if (isset($this->data['_method'])) {
$isArray = is_array($this->data);
if ($isArray && isset($this->data['_method'])) {
if (!empty($_SERVER)) {
$_SERVER['REQUEST_METHOD'] = $this->data['_method'];
} else {
@ -183,8 +184,7 @@ class CakeRequest implements ArrayAccess {
}
unset($this->data['_method']);
}
if (isset($this->data['data'])) {
if ($isArray && isset($this->data['data'])) {
$data = $this->data['data'];
if (count($this->data) <= 1) {
$this->data = $data;

View file

@ -300,6 +300,22 @@ class CakeRequestTest extends CakeTestCase {
$this->assertEquals($data, $request->data);
}
/**
* test parsing json PUT data into the object.
*
* @return void
*/
public function testPutParsingJSON() {
$_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['CONTENT_TYPE'] = 'application/json';
$request = $this->getMock('TestCakeRequest', array('_readInput'));
$request->expects($this->at(0))->method('_readInput')
->will($this->returnValue('{Article":["title"]}'));
$request->reConstruct();
$this->assertEquals('{Article":["title"]}', $request->data);
}
/**
* test parsing of FILES array
*