Permalink
Browse files

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
  • Loading branch information...
2 parents 60abc7e + c3a7a60 commit 36e91eaa663826a6cbb4d3e94915aad16f667cca @fabpot fabpot committed Dec 13, 2012
Showing with 39 additions and 2 deletions.
  1. +6 −2 Encoder/XmlEncoder.php
  2. +33 −0 Tests/Encoder/XmlEncoderTest.php
View
@@ -243,11 +243,15 @@ private function parseXml($node)
if ($key === 'item') {
if (isset($value['@key'])) {
- $data[(string) $value['@key']] = $value['#'];
+ if (isset($value['#'])) {
+ $data[(string) $value['@key']] = $value['#'];
+ } else {
+ $data[(string) $value['@key']] = $value;
+ }
} else {
$data['item'][] = $value;
}
- } elseif (array_key_exists($key, $data)) {
+ } elseif (array_key_exists($key, $data) || $key == "entry") {
if ((false === is_array($data[$key])) || (false === isset($data[$key][0]))) {
$data[$key] = array($data[$key]);
}
@@ -251,6 +251,39 @@ public function testDecodeArray()
$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
}
+ public function testDecodeWithoutItemHash()
+ {
+ $obj = new ScalarDummy;
+ $obj->xmlFoo = array(
+ 'foo-bar' => array(
+ '@key' => "value",
+ 'item' => array("@key" => 'key', "key-val" => 'val')
+ ),
+ 'Foo' => array(
+ 'Bar' => "Test",
+ '@Type' => 'test'
+ ),
+ 'föo_bär' => 'a',
+ "Bar" => array(1,2,3),
+ 'a' => 'b',
+ );
+ $expected = array(
+ 'foo-bar' => array(
+ '@key' => "value",
+ 'key' => array('@key' => 'key', "key-val" => 'val')
+ ),
+ 'Foo' => array(
+ 'Bar' => "Test",
+ '@Type' => 'test'
+ ),
+ 'föo_bär' => 'a',
+ "Bar" => array(1,2,3),
+ 'a' => 'b',
+ );
+ $xml = $this->encoder->encode($obj, 'xml');
+ $this->assertEquals($expected, $this->encoder->decode($xml, 'xml'));
+ }
+
public function testPreventsComplexExternalEntities()
{
$oldCwd = getcwd();

0 comments on commit 36e91ea

Please sign in to comment.