diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index bd445b7dc831a..c672c0b598b9e 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -159,15 +159,7 @@ public function decode(string $data, string $format, array $context = []) 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]); } /** diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php index 657281a8d8f0e..6e1fb514c498a 100644 --- a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php +++ b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php @@ -315,6 +315,21 @@ public function testDecodeFloatAttributeWithZeroWholeNumber() $this->assertSame(['@index' => 0.123, '#' => 'Name'], $this->encoder->decode($source, 'xml')); } + public function testNoTypeCastRootAttribute() + { + $source = << + +XML; + + $data = $this->encoder->decode($source, 'xml', ['xml_type_cast_attributes' => false]); + $expected = [ + '@a' => '123', + '#' => '', + ]; + $this->assertSame($expected, $data); + } + public function testNoTypeCastAttribute() { $source = << pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy