diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index f05319f87..0fbc2855a 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -145,7 +145,14 @@ class CakeRequest implements ArrayAccess { /** * process the post data and set what is there into the object. - * processed data is available at $this->data + * processed data is available at `$this->data` + * + * Will merge POST vars prefixed with `data`, and ones without + * into a single array. Variables prefixed with `data` will overwrite those without. + * + * If you have mixed POST values be careful not to make any top level keys numeric + * containing arrays. Set::merge() is used to merge data, and it has possibly + * unexpected behavior in this situation. * * @return void */ @@ -165,8 +172,14 @@ class CakeRequest implements ArrayAccess { } unset($this->data['_method']); } + $data = $this->data; if (isset($this->data['data'])) { $data = $this->data['data']; + } + if (count($this->data) <= 1) { + $this->data = $data; + } + if (count($this->data) > 1) { unset($this->data['data']); $this->data = Set::merge($this->data, $data); } diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 7bba6bd56..d7fa4cbf0 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -177,6 +177,19 @@ class CakeRequestTest extends CakeTestCase { $_POST = array('one' => 1, 'two' => 'three'); $request = new CakeRequest('some/path'); $this->assertEquals($_POST, $request->data); + + $_POST = array( + 'data' => array( + 'Article' => array('title' => 'Testing'), + ), + 'action' => 'update' + ); + $request = new CakeRequest('some/path'); + $expected = array( + 'Article' => array('title' => 'Testing'), + 'action' => 'update' + ); + $this->assertEquals($expected, $request->data); } /**