Permalink
Browse files

Fixing bug when value is '0', it was generating a blank node.

  • Loading branch information...
1 parent 20ef932 commit 317049b7369025db730598f23a84bac425832e36 @renan renan committed Sep 18, 2009
Showing with 17 additions and 4 deletions.
  1. +2 −2 cake/libs/xml.php
  2. +15 −2 cake/tests/cases/libs/xml.test.php
View
@@ -227,7 +227,7 @@ function normalize($object, $keyName = null, $options = array()) {
$chldObjs = get_object_vars($object);
} elseif (is_array($object)) {
$chldObjs = $object;
- } elseif (!empty($object) || $object === 0) {
+ } elseif (!empty($object) || $object === 0 || $object === '0') {
$node->createTextNode($object);
}
$attr = array();
@@ -268,7 +268,7 @@ function normalize($object, $keyName = null, $options = array()) {
$node->normalize($val, $n, $options);
} elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) {
$tmp =& $node->createElement($key);
- if (!empty($val) || $val === 0) {
+ if (!empty($val) || $val === 0 || $val === '0') {
$tmp->createTextNode($val);
}
} elseif ($options['format'] == 'attributes') {
@@ -177,6 +177,19 @@ function testSimpleObject() {
$this->assertEqual($expected, $result);
}
/**
+ * testSimpleArrayWithZeroValues method
+ *
+ * @access public
+ * @return void
+ */
+ function testSimpleArrayWithZeroValues() {
+ $xml = new Xml(array('zero_string' => '0', 'zero_integer' => 0), array('format' => 'tags'));
+
+ $result = $xml->toString(false);
+ $expected = '<zero_string>0</zero_string><zero_integer>0</zero_integer>';
+ $this->assertEqual($expected, $result);
+ }
+/**
* testHeader method
*
* @access public
@@ -761,7 +774,7 @@ function testElementCollapsing() {
}
/**
* test that empty values do not casefold collapse
- *
+ *
* @see http://code.cakephp.org/tickets/view/8
* @return void
**/
@@ -797,7 +810,7 @@ function testCaseFoldingWithEmptyValues() {
<name>varchar(45)</name>
</User>
</method>';
-
+
$xml =& new XML($emptyValue);
$expected = array(
'Method' => array(

0 comments on commit 317049b

Please sign in to comment.