Remove un-necessary Set::merge().

Using Set::merge() on an empty array causes issues with out of order
numeric keys. Only merge if necessary.

Fixes #2595
This commit is contained in:
mark_story 2012-02-18 22:18:16 -05:00
parent 2ddc3873c2
commit 89df484fc5
2 changed files with 27 additions and 1 deletions

View file

@ -145,7 +145,14 @@ class CakeRequest implements ArrayAccess {
/** /**
* process the post data and set what is there into the object. * 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 * @return void
*/ */
@ -165,8 +172,14 @@ class CakeRequest implements ArrayAccess {
} }
unset($this->data['_method']); unset($this->data['_method']);
} }
$data = $this->data;
if (isset($this->data['data'])) { if (isset($this->data['data'])) {
$data = $this->data['data']; $data = $this->data['data'];
}
if (count($this->data) <= 1) {
$this->data = $data;
}
if (count($this->data) > 1) {
unset($this->data['data']); unset($this->data['data']);
$this->data = Set::merge($this->data, $data); $this->data = Set::merge($this->data, $data);
} }

View file

@ -177,6 +177,19 @@ class CakeRequestTest extends CakeTestCase {
$_POST = array('one' => 1, 'two' => 'three'); $_POST = array('one' => 1, 'two' => 'three');
$request = new CakeRequest('some/path'); $request = new CakeRequest('some/path');
$this->assertEquals($_POST, $request->data); $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);
} }
/** /**