Skip to content

Commit 36e91ea

Browse files
committed
Merge branch '2.1'
* 2.1: [Console] Add support for parsing terminal width/height on localized windows, fixes #5742 [Form] Fixed treatment of countables and traversables in Form::isEmpty() refactor ControllerNameParser [Form] Fixed FileType not to throw an exception when bound empty - Test undefined index # Maintain array structure Check if key # is defined in $value Update src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf
2 parents 60abc7e + c3a7a60 commit 36e91ea

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

Encoder/XmlEncoder.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,15 @@ private function parseXml($node)
243243

244244
if ($key === 'item') {
245245
if (isset($value['@key'])) {
246-
$data[(string) $value['@key']] = $value['#'];
246+
if (isset($value['#'])) {
247+
$data[(string) $value['@key']] = $value['#'];
248+
} else {
249+
$data[(string) $value['@key']] = $value;
250+
}
247251
} else {
248252
$data['item'][] = $value;
249253
}
250-
} elseif (array_key_exists($key, $data)) {
254+
} elseif (array_key_exists($key, $data) || $key == "entry") {
251255
if ((false === is_array($data[$key])) || (false === isset($data[$key][0]))) {
252256
$data[$key] = array($data[$key]);
253257
}

Tests/Encoder/XmlEncoderTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,39 @@ public function testDecodeArray()
251251
$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
252252
}
253253

254+
public function testDecodeWithoutItemHash()
255+
{
256+
$obj = new ScalarDummy;
257+
$obj->xmlFoo = array(
258+
'foo-bar' => array(
259+
'@key' => "value",
260+
'item' => array("@key" => 'key', "key-val" => 'val')
261+
),
262+
'Foo' => array(
263+
'Bar' => "Test",
264+
'@Type' => 'test'
265+
),
266+
'föo_bär' => 'a',
267+
"Bar" => array(1,2,3),
268+
'a' => 'b',
269+
);
270+
$expected = array(
271+
'foo-bar' => array(
272+
'@key' => "value",
273+
'key' => array('@key' => 'key', "key-val" => 'val')
274+
),
275+
'Foo' => array(
276+
'Bar' => "Test",
277+
'@Type' => 'test'
278+
),
279+
'föo_bär' => 'a',
280+
"Bar" => array(1,2,3),
281+
'a' => 'b',
282+
);
283+
$xml = $this->encoder->encode($obj, 'xml');
284+
$this->assertEquals($expected, $this->encoder->decode($xml, 'xml'));
285+
}
286+
254287
public function testPreventsComplexExternalEntities()
255288
{
256289
$oldCwd = getcwd();

0 commit comments

Comments
 (0)