Permalink
Browse files

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>
  • Loading branch information...
1 parent e61f636 commit e10f6f57a3c186f91f264f8b016e2259b682d644 @rodrigorm rodrigorm committed with markstory Jul 2, 2012
Showing with 19 additions and 3 deletions.
  1. +3 −3 lib/Cake/Network/CakeRequest.php
  2. +16 −0 lib/Cake/Test/Case/Network/CakeRequestTest.php
View
6 lib/Cake/Network/CakeRequest.php
@@ -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;
View
16 lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -301,6 +301,22 @@ public function testPutParsing() {
}
/**
+ * 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
*
* @return void

0 comments on commit e10f6f5

Please sign in to comment.