Skip to content
This repository
Browse code

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
Mark Story authored
3  cake/libs/xml.php
@@ -275,6 +275,9 @@ function normalize($object, $keyName = null, $options = array()) {
275 275
 
276 276
 							$node->normalize($val, $n, $options);
277 277
 						} elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) {
  278
+							if ($options['slug'] == true) {
  279
+								$key = Inflector::slug(Inflector::underscore($key));
  280
+							}
278 281
 							$tmp =& $node->createElement($key);
279 282
 							if (!empty($val) || $val === 0 || $val === '0') {
280 283
 								$tmp->createTextNode($val);
13  cake/tests/cases/libs/xml.test.php
@@ -1624,4 +1624,17 @@ function testToArrayAlternate() {
1624 1624
 		$this->assertIdentical($result, $expected);
1625 1625
 	}
1626 1626
 	
  1627
+
  1628
+	function testToStringSlugging() {
  1629
+		$array = array(
  1630
+			'Response' => array(
  1631
+				'OneKey' => 'foo',
  1632
+				'TwoKey' => array('bar', 'baz')
  1633
+			)
  1634
+		);
  1635
+		$xml = new Xml($array, array('format' => 'tags'));
  1636
+		$result = $xml->toString(array('cdata' => false));
  1637
+		$expected = '<response><one_key>foo</one_key><two_key>bar</two_key><two_key>baz</two_key></response>';
  1638
+		$this->assertEqual($result, $expected);
  1639
+	}
1627 1640
 }

0 notes on commit 3f58509

Please sign in to comment.
Something went wrong with that request. Please try again.