Skip to content

Commit

Permalink
Fixing bug when value is '0', it was generating a blank node.
Browse files Browse the repository at this point in the history
  • Loading branch information
renan committed Sep 18, 2009
1 parent 20ef932 commit 317049b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cake/libs/xml.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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') {
Expand Down
17 changes: 15 additions & 2 deletions cake/tests/cases/libs/xml.test.php
Expand Up @@ -176,6 +176,19 @@ function testSimpleObject() {
$expected = '<hello><![CDATA[world]]></hello>';
$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
*
Expand Down Expand Up @@ -761,7 +774,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 @@ -797,7 +810,7 @@ function testCaseFoldingWithEmptyValues() {
<name>varchar(45)</name>
</User>
</method>';

$xml =& new XML($emptyValue);
$expected = array(
'Method' => array(
Expand Down

0 comments on commit 317049b

Please sign in to comment.