From 317049b7369025db730598f23a84bac425832e36 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 17 Sep 2009 23:08:32 -0300 Subject: [PATCH] Fixing bug when value is '0', it was generating a blank node. --- cake/libs/xml.php | 4 ++-- cake/tests/cases/libs/xml.test.php | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cake/libs/xml.php b/cake/libs/xml.php index 0d91825bc3a..437719a597e 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -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') { diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index acff6c89bd5..793c573eb55 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -176,6 +176,19 @@ function testSimpleObject() { $expected = ''; $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 = '00'; + $this->assertEqual($expected, $result); + } /** * testHeader method * @@ -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() { varchar(45) '; - + $xml =& new XML($emptyValue); $expected = array( 'Method' => array(