Skip to content

Commit

Permalink
Merge branch '5.4' into 6.3
Browse files Browse the repository at this point in the history
* 5.4:
  [Serializer] Fix parsing XML root node attributes
  • Loading branch information
nicolas-grekas committed Sep 29, 2023
2 parents 1c1a5f9 + b893175 commit 855fc05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
10 changes: 1 addition & 9 deletions Encoder/XmlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,7 @@ public function decode(string $data, string $format, array $context = []): mixed
return $rootNode->nodeValue;
}

$data = [];

foreach ($rootNode->attributes as $attrKey => $attr) {
$data['@'.$attrKey] = $attr->nodeValue;
}

$data['#'] = $rootNode->nodeValue;

return $data;
return array_merge($this->parseXmlAttributes($rootNode, $context), ['#' => $rootNode->nodeValue]);
}

public function supportsEncoding(string $format): bool
Expand Down
15 changes: 15 additions & 0 deletions Tests/Encoder/XmlEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,21 @@ public function testDecodeFloatAttributeWithZeroWholeNumber()
$this->assertSame(['@index' => 0.123, '#' => 'Name'], $this->encoder->decode($source, 'xml'));
}

public function testNoTypeCastRootAttribute()
{
$source = <<<XML
<?xml version="1.0"?>
<document a="123"></document>
XML;

$data = $this->encoder->decode($source, 'xml', ['xml_type_cast_attributes' => false]);
$expected = [
'@a' => '123',
'#' => '',
];
$this->assertSame($expected, $data);
}

public function testNoTypeCastAttribute()
{
$source = <<<XML
Expand Down

0 comments on commit 855fc05

Please sign in to comment.