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
This commit is contained in:
mark_story 2012-10-31 21:02:47 -04:00
parent 26d8351af4
commit 8035b37df2
2 changed files with 9 additions and 7 deletions

View file

@ -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);

View file

@ -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']);
}
/**