Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing Xml::toString() not slugging elements with no children.

Thanks to jeremyharris for the patch.
Fixes #903
  • Loading branch information...
commit 3f5850913a2b75815531662bc9d5ca169a5a66a5 1 parent b76901e
@markstory markstory authored
Showing with 16 additions and 0 deletions.
  1. +3 −0  cake/libs/xml.php
  2. +13 −0 cake/tests/cases/libs/xml.test.php
View
3  cake/libs/xml.php
@@ -275,6 +275,9 @@ function normalize($object, $keyName = null, $options = array()) {
$node->normalize($val, $n, $options);
} elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) {
+ if ($options['slug'] == true) {
+ $key = Inflector::slug(Inflector::underscore($key));
+ }
$tmp =& $node->createElement($key);
if (!empty($val) || $val === 0 || $val === '0') {
$tmp->createTextNode($val);
View
13 cake/tests/cases/libs/xml.test.php
@@ -1624,4 +1624,17 @@ function testToArrayAlternate() {
$this->assertIdentical($result, $expected);
}
+
+ function testToStringSlugging() {
+ $array = array(
+ 'Response' => array(
+ 'OneKey' => 'foo',
+ 'TwoKey' => array('bar', 'baz')
+ )
+ );
+ $xml = new Xml($array, array('format' => 'tags'));
+ $result = $xml->toString(array('cdata' => false));
+ $expected = '<response><one_key>foo</one_key><two_key>bar</two_key><two_key>baz</two_key></response>';
+ $this->assertEqual($result, $expected);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.