Skip to content

Commit

Permalink
Fix notice error when parsing input data.
Browse files Browse the repository at this point in the history
Prevent error in CakeRequest from parsing input data in
PUT and DELETE requests.

Fixes #3002

Signed-off-by: mark_story <mark@mark-story.com>
  • Loading branch information
rodrigorm authored and markstory committed Jul 6, 2012
1 parent e61f636 commit e10f6f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Cake/Network/CakeRequest.php
Expand Up @@ -175,16 +175,16 @@ protected function _processPost() {
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 {
$_ENV['REQUEST_METHOD'] = $this->data['_method'];
}
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;
Expand Down
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/Network/CakeRequestTest.php
Expand Up @@ -300,6 +300,22 @@ public function testPutParsing() {
$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
*
Expand Down

0 comments on commit e10f6f5

Please sign in to comment.