Browse Source

Merge pull request #1338 from aymericderbois/FixErrorWithZeroValueXml

Fix bug in Xml::_createChild Method
Mark Story 13 years ago
parent
commit
0f38dbd485
2 changed files with 14 additions and 1 deletions
  1. 13 0
      lib/Cake/Test/Case/Utility/XmlTest.php
  2. 1 1
      lib/Cake/Utility/Xml.php

+ 13 - 0
lib/Cake/Test/Case/Utility/XmlTest.php

@@ -375,6 +375,19 @@ XML;
 		$obj = Xml::fromArray($xml, 'attributes');
 		$xmlText = '<' . '?xml version="1.0" encoding="UTF-8"?><tags><tag id="1">defect</tag></tags>';
 		$this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
+
+		$xml = array(
+			'tag' => array(
+				'@' => 0,
+				'@test' => 'A test'
+			)
+		);
+		$obj = Xml::fromArray($xml);
+		$xmlText = <<<XML
+<?xml version="1.0" encoding="UTF-8"?>
+<tag test="A test">0</tag>
+XML;
+		$this->assertXmlStringEqualsXmlString($xmlText, $obj->asXML());
 	}
 
 /**

+ 1 - 1
lib/Cake/Utility/Xml.php

@@ -310,7 +310,7 @@ class Xml {
 		}
 
 		$child = $dom->createElement($key);
-		if ($childValue) {
+		if (!is_null($childValue)) {
 			$child->appendChild($dom->createTextNode($childValue));
 		}
 		if ($childNS) {