Skip to content

Commit

Permalink
Fix a problem of tag values which is not taken into account
Browse files Browse the repository at this point in the history
(when equal to zero) when passing an XML object to an array.
  • Loading branch information
aymericderbois committed May 7, 2013
1 parent d01d291 commit ca6612b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/Cake/Test/Case/Utility/XmlTest.php
Expand Up @@ -644,6 +644,16 @@ public function testToArray() {
)
);
$this->assertEquals($expected, Xml::toArray($obj));

$xml = '<tag type="myType">0</tag>';
$obj = Xml::build($xml);
$expected = array(
'tag' => array(
'@type' => 'myType',
'@' => 0
)
);
$this->assertEquals($expected, Xml::toArray($obj));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Xml.php
Expand Up @@ -360,7 +360,7 @@ protected static function _toArray($xml, &$parentData, $ns, $namespaces) {
$asString = trim((string)$xml);
if (empty($data)) {
$data = $asString;
} elseif (!empty($asString)) {
} elseif (strlen($asString) > 0) {
$data['@'] = $asString;
}

Expand Down

0 comments on commit ca6612b

Please sign in to comment.