Skip to content

Commit

Permalink
Fixing Xml::toArray() when blank nodes are provided. Fixes #87.
Browse files Browse the repository at this point in the history
  • Loading branch information
renan committed Sep 22, 2009
1 parent d5376e6 commit 42fac9e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
7 changes: 3 additions & 4 deletions cake/libs/xml.php
Expand Up @@ -704,7 +704,6 @@ function toArray($camelize = true) {
continue;
} elseif (isset($child->children[0]) && is_a($child->children[0], 'XmlTextNode')) {
$value = $child->children[0]->value;

if ($child->attributes) {
$value = array_merge(array('value' => $value), $child->attributes);
}
Expand All @@ -720,10 +719,10 @@ function toArray($camelize = true) {
continue;
} elseif (count($child->children) === 0 && $child->value == '') {
$value = $child->attributes;
if (isset($out[$child->name]) || isset($multi[$key])) {
if (isset($out[$key]) || isset($multi[$key])) {
if (!isset($multi[$key])) {
$multi[$key] = array($out[$child->name]);
unset($out[$child->name]);
$multi[$key] = array($out[$key]);
unset($out[$key]);
}
$multi[$key][] = $value;
} elseif (!empty($value)) {
Expand Down
26 changes: 24 additions & 2 deletions cake/tests/cases/libs/xml.test.php
Expand Up @@ -784,7 +784,7 @@ function testElementCollapsing() {

/**
* test that empty values do not casefold collapse
*
*
* @see http://code.cakephp.org/tickets/view/8
* @return void
**/
Expand Down Expand Up @@ -820,7 +820,7 @@ function testCaseFoldingWithEmptyValues() {
<name>varchar(45)</name>
</User>
</method>';

$xml =& new XML($emptyValue);
$expected = array(
'Method' => array(
Expand Down Expand Up @@ -1204,7 +1204,29 @@ function testToArray() {
)
)
));
$this->assertEqual($result, $expected);

$text = '<?xml version="1.0" encoding="UTF-8"?>
<root>
<child id="1" other="1" />
<child id="2" other="1" />
<child id="3" other="1" />
<child id="4" other="1" />
<child id="5" other="1" />
</root>';
$xml = new Xml($text);
$result = $xml->toArray();
$expected = array(
'Root' => array(
'Child' => array(
array('id' => 1, 'other' => 1),
array('id' => 2, 'other' => 1),
array('id' => 3, 'other' => 1),
array('id' => 4, 'other' => 1),
array('id' => 5, 'other' => 1)
)
)
);
$this->assertEqual($result, $expected);
}

Expand Down

0 comments on commit 42fac9e

Please sign in to comment.