diff --git a/cake/libs/view/helpers/xml.php b/cake/libs/view/helpers/xml.php index fa1917448..afb2ccb7a 100644 --- a/cake/libs/view/helpers/xml.php +++ b/cake/libs/view/helpers/xml.php @@ -126,15 +126,15 @@ class XmlHelper extends AppHelper { * @return string XML */ function elem($name, $attrib = array(), $content = null, $endTag = true) { - $ns = null; + if (isset($attrib['namespace'])) { $ns = $attrib['namespace'] . ':'; unset($attrib['namespace']); } $out = "<{$ns}{$name}" . $this->__composeAttributes($attrib); - if (empty($content) && $endTag) { + if ((empty($content) && $content !== 0) && $endTag) { $out .= ' />'; } else { $out .= '>' . $this->__composeContent($content); @@ -142,7 +142,6 @@ class XmlHelper extends AppHelper { $out .= ""; } } - return $this->output($out); } /** diff --git a/cake/tests/cases/libs/view/helpers/xml.test.php b/cake/tests/cases/libs/view/helpers/xml.test.php index ffbd81d01..a65b55613 100644 --- a/cake/tests/cases/libs/view/helpers/xml.test.php +++ b/cake/tests/cases/libs/view/helpers/xml.test.php @@ -65,6 +65,12 @@ class XmlHelperTest extends UnitTestCase { $this->assertEqual($manager->namespaces, $expected); } + function testRenderZeroElement() { + $result = $this->Xml->elem('count', null, 0); + $expected = '0'; + $this->assertEqual($result, $expected); + } + function tearDown() { unset($this->Xml); }