Skip to content
Permalink
Browse files

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
  • Loading branch information...
markstory committed Nov 1, 2012
1 parent 26d8351 commit 8035b37df2c18771e2e14fd6fdf847becc8f9297
Showing with 9 additions and 7 deletions.
  1. +6 −5 lib/Cake/Network/CakeRequest.php
  2. +3 −2 lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -162,11 +162,12 @@ public function __construct($url = null, $parseEnvironment = true) {
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);
@@ -311,9 +311,10 @@ public function testPutParsingJSON() {
$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']);
}
/**

0 comments on commit 8035b37

Please sign in to comment.
You can’t perform that action at this time.