Browse Source

Only set $request->data with PUT/DELETE when it can be decoded.

Setting $request->data to the raw put data isn't overly useful unless it
can be decoded.  Generally $request->data is expected to be an array,
when its a string things can go funny.

Fixes #3320
mark_story 13 years ago
parent
commit
8035b37df2

+ 6 - 5
lib/Cake/Network/CakeRequest.php

@@ -162,11 +162,12 @@ class CakeRequest implements ArrayAccess {
 	protected function _processPost() {
 		if ($_POST) {
 			$this->data = $_POST;
-		} elseif ($this->is('put') || $this->is('delete')) {
-			$this->data = $this->_readInput();
-			if (strpos(env('CONTENT_TYPE'), 'application/x-www-form-urlencoded') === 0) {
-				parse_str($this->data, $this->data);
-			}
+		} elseif (
+			($this->is('put') || $this->is('delete')) &&
+			strpos(env('CONTENT_TYPE'), 'application/x-www-form-urlencoded') === 0
+		) {
+				$data = $this->_readInput();
+				parse_str($data, $this->data);
 		}
 		if (ini_get('magic_quotes_gpc') === '1') {
 			$this->data = stripslashes_deep($this->data);

+ 3 - 2
lib/Cake/Test/Case/Network/CakeRequestTest.php

@@ -311,9 +311,10 @@ class CakeRequestTest extends CakeTestCase {
 
 		$request = $this->getMock('TestCakeRequest', array('_readInput'));
 		$request->expects($this->at(0))->method('_readInput')
-			->will($this->returnValue('{Article":["title"]}'));
+			->will($this->returnValue('{"Article":["title"]}'));
 		$request->reConstruct();
-		$this->assertEquals('{Article":["title"]}', $request->data);
+		$result = $request->input('json_decode', true);
+		$this->assertEquals(array('title'), $result['Article']);
 	}
 
 /**