diff --git a/cake/libs/xml.php b/cake/libs/xml.php index 845068514..509d916b0 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -607,6 +607,9 @@ class XmlNode extends Object { if (is_array($this->attributes) && count($this->attributes) > 0) { foreach ($this->attributes as $key => $val) { + if (is_bool($val) && $val === false) { + $val = 0; + } $d .= ' ' . $key . '="' . htmlspecialchars($val, ENT_QUOTES, Configure::read('App.encoding')) . '"'; } } diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index eec558641..9cbf5e87b 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -97,6 +97,38 @@ class XmlTest extends CakeTestCase { $result = preg_replace("/\n/",'', $xml->toString(false)); $this->assertEqual($result, $expected); } + +/** + * test serialization of boolean and null values. false = 0, true = 1, null = '' + * + * @return void + **/ + function testSerializationOfBooleanAndBooleanishValues() { + $xml =& new Xml(array('data' => array('example' => false))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => true))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => null))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => 0))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean-ish values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => 1))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean-ish values incorrectly handled. %s'); + } /** * testSimpleArray method *