8000 Merge branch '5.4' into 6.3 · symfony/symfony@10c8260 · GitHub
[go: up one dir, main page]

Skip to content

Commit 10c8260

Browse files
Merge branch '5.4' into 6.3
* 5.4: [Serializer] Fix parsing XML root node attributes
2 parents 69ef02e + d8e20aa commit 10c8260

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/Symfony/Component/Serializer/Encoder/XmlEncoder.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,7 @@ public function decode(string $data, string $format, array $context = []): mixed
154154
return $rootNode->nodeValue;
155155
}
156156

157-
$data = [];
158-
159-
foreach ($rootNode->attributes as $attrKey => $attr) {
160-
$data['@'.$attrKey] = $attr->nodeValue;
161-
}
162-
163-
$data['#'] = $rootNode->nodeValue;
164-
165-
return $data;
157+
return array_merge($this->parseXmlAttributes($rootNode, $context), ['#' => $rootNode->nodeValue]);
166158
}
167159

168160
public function supportsEncoding(string $format): bool

src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,21 @@ public function testDecodeFloatAttributeWithZeroWholeNumber()
317317
$this->assertSame(['@index' => 0.123, '#' => 'Name'], $this->encoder->decode($source, 'xml'));
318318
}
319319

320+
public function testNoTypeCastRootAttribute()
321+
{
322+
$source = <<<XML
323+
<?xml version="1.0"?>
324+
<document a="123"></document>
325+
XML;
326+
327+
$data = $this->encoder->decode($source, 'xml', ['xml_type_cast_attributes' => false]);
328+
$expected = [
329+
'@a' => '123',
330+
'#' => '',
331+
];
332+
$this->assertSame($expected, $data);
333+
}
334+
320335
public function testNoTypeCastAttribute()
321336
{
322337
$source = <<<XML

0 commit comments

Comments
 (0)
0