diff --git a/lib/Cake/Test/Case/Utility/XmlTest.php b/lib/Cake/Test/Case/Utility/XmlTest.php index d1bf8d1b2..7eb68f823 100644 --- a/lib/Cake/Test/Case/Utility/XmlTest.php +++ b/lib/Cake/Test/Case/Utility/XmlTest.php @@ -322,6 +322,43 @@ class XmlTest extends CakeTestCase { $this->assertEquals(str_replace(array("\r", "\n"), '', $obj->asXML()), $xmlText); } +/** + * Test non-sequential keys in list types. + * + * @return void + */ + public function testFromArrayNonSequentialKeys() { + $xmlArray = array( + 'Event' => array( + array( + 'id' => '235', + 'Attribute' => array( + 0 => array( + 'id' => '9646', + ), + 2 => array( + 'id' => '9647', + ) + ) + ) + ) + ); + $obj = Xml::fromArray($xmlArray); + $expected = << + + 235 + + 9646 + + + 9647 + + +XML; + $this->assertXmlStringEqualsXmlString($expected, $obj->asXML()); + } + /** * data provider for fromArray() failures * diff --git a/lib/Cake/Utility/Xml.php b/lib/Cake/Utility/Xml.php index 70044471e..6b96f7f61 100644 --- a/lib/Cake/Utility/Xml.php +++ b/lib/Cake/Utility/Xml.php @@ -230,7 +230,7 @@ class Xml { if ($key[0] === '@') { throw new XmlException(__d('cake_dev', 'Invalid array')); } - if (array_keys($value) === range(0, count($value) - 1)) { // List + if (is_numeric(implode(array_keys($value), ''))) { // List foreach ($value as $item) { $itemData = compact('dom', 'node', 'key', 'format'); $itemData['value'] = $item;