Skip to content

Commit c1bfaa1

Browse files
committed
[Serializer] XmlEncoder: don't cast padded strings
1 parent 5328c4b commit c1bfaa1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private function parseXmlAttributes(\DOMNode $node, array $context = [])
303303
$typeCastAttributes = $this->resolveXmlTypeCastAttributes($context);
304304

305305
foreach ($node->attributes as $attr) {
306-
if (!is_numeric($attr->nodeValue) || !$typeCastAttributes) {
306+
if (!is_numeric($attr->nodeValue) || !$typeCastAttributes || (isset($attr->nodeValue[1]) && '0' === $attr->nodeValue[0])) {
307307
$data['@'.$attr->nodeName] = $attr->nodeValue;
308308

309309
continue;

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

+11
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,17 @@ public function testNoTypeCastAttribute()
306306
$this->assertSame($expected, $data);
307307
}
308308

309+
public function testDoesNotTypeCastStringsStartingWith0()
310+
{
311+
$source = <<<XML
312+
<?xml version="1.0"?>
313+
<document a="018"></document>
314+
XML;
315+
316+
$data = $this->encoder->decode($source, 'xml');
317+
$this->assertSame('018', $data['@a']);
318+
}
319+
309320
public function testEncode()
310321
{
311322
$source = $this->getXmlSource();

0 commit comments

Comments
 (0)