mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing Xml::toArray() Where camelcased data was collapsed and corrupted. Causing unpredictable data structures with empty tags. Minor changes to existing behavior. See modified test cases. Fixes #8
This commit is contained in:
parent
ab50bbe595
commit
5a971ddbf0
2 changed files with 58 additions and 5 deletions
|
@ -676,7 +676,6 @@ class XmlNode extends Object {
|
|||
if ($child->attributes) {
|
||||
$value = array_merge(array('value' => $value), $child->attributes);
|
||||
}
|
||||
|
||||
if (isset($out[$child->name]) || isset($multi[$key])) {
|
||||
if (!isset($multi[$key])) {
|
||||
$multi[$key] = array($out[$child->name]);
|
||||
|
@ -689,15 +688,16 @@ class XmlNode extends Object {
|
|||
continue;
|
||||
} elseif (count($child->children) === 0 && $child->value == '') {
|
||||
$value = $child->attributes;
|
||||
|
||||
if (isset($out[$child->name]) || isset($multi[$key])) {
|
||||
if (!isset($multi[$key])) {
|
||||
$multi[$key] = array($out[$child->name]);
|
||||
unset($out[$child->name]);
|
||||
}
|
||||
$multi[$key][] = $value;
|
||||
} else {
|
||||
} elseif (!empty($value)) {
|
||||
$out[$key] = $value;
|
||||
} else {
|
||||
$out[$child->name] = $value;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
|
@ -909,7 +909,6 @@ class Xml extends XmlNode {
|
|||
for ($i = 0; $i < $count; $i++) {
|
||||
$data = $vals[$i];
|
||||
$data += array('tag' => null, 'value' => null, 'attributes' => array());
|
||||
|
||||
switch ($data['type']) {
|
||||
case "open" :
|
||||
$xml =& $xml->createElement($data['tag'], $data['value'], $data['attributes']);
|
||||
|
|
|
@ -759,6 +759,60 @@ class XmlTest extends CakeTestCase {
|
|||
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* test that empty values do not casefold collapse
|
||||
*
|
||||
* @see http://code.cakephp.org/tickets/view/8
|
||||
* @return void
|
||||
**/
|
||||
function testCaseFoldingWithEmptyValues() {
|
||||
$filledValue = '<method name="set_user_settings">
|
||||
<title>update user information</title>
|
||||
<user>1</user>
|
||||
<User>
|
||||
<id>1</id>
|
||||
<name>varchar(45)</name>
|
||||
</User>
|
||||
</method>';
|
||||
$xml =& new XML($filledValue);
|
||||
$expected = array(
|
||||
'Method' => array(
|
||||
'name' => 'set_user_settings',
|
||||
'title' => 'update user information',
|
||||
'user' => '1',
|
||||
'User' => array(
|
||||
'id' => 1,
|
||||
'name' => 'varchar(45)',
|
||||
),
|
||||
)
|
||||
);
|
||||
$result = $xml->toArray();
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$emptyValue ='<method name="set_user_settings">
|
||||
<title>update user information</title>
|
||||
<user></user>
|
||||
<User>
|
||||
<id>1</id>
|
||||
<name>varchar(45)</name>
|
||||
</User>
|
||||
</method>';
|
||||
|
||||
$xml =& new XML($emptyValue);
|
||||
$expected = array(
|
||||
'Method' => array(
|
||||
'name' => 'set_user_settings',
|
||||
'title' => 'update user information',
|
||||
'user' => array(),
|
||||
'User' => array(
|
||||
'id' => 1,
|
||||
'name' => 'varchar(45)',
|
||||
),
|
||||
)
|
||||
);
|
||||
$result = $xml->toArray();
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testMixedParsing method
|
||||
*
|
||||
|
@ -921,7 +975,7 @@ class XmlTest extends CakeTestCase {
|
|||
'Example' => array(
|
||||
'Item' => array(
|
||||
'title' => 'An example of a correctly reversed XMLNode',
|
||||
'Desc' => array(),
|
||||
'desc' => array(),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue