Permalink
Browse files

Fix a problem of tag values which is not taken into account

(when equal to zero) when passing an XML object to an array.
  • Loading branch information...
1 parent d01d291 commit ca6612bc8b0ab6de735c1baf216d64a079ac9872 @aymericderbois aymericderbois committed Apr 17, 2013
Showing with 11 additions and 1 deletion.
  1. +10 −0 lib/Cake/Test/Case/Utility/XmlTest.php
  2. +1 −1 lib/Cake/Utility/Xml.php
@@ -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));
}
/**
View
@@ -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;
}

0 comments on commit ca6612b

Please sign in to comment.