mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix issue with non-sequential array keys.
Xml::fromArray() should not cause errors with non-sequential numeric array keys. Fixes #2580
This commit is contained in:
parent
128c719bd0
commit
73b0345ff4
2 changed files with 38 additions and 1 deletions
|
@ -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 = <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Event>
|
||||
<id>235</id>
|
||||
<Attribute>
|
||||
<id>9646</id>
|
||||
</Attribute>
|
||||
<Attribute>
|
||||
<id>9647</id>
|
||||
</Attribute>
|
||||
</Event>
|
||||
XML;
|
||||
$this->assertXmlStringEqualsXmlString($expected, $obj->asXML());
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for fromArray() failures
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue