Skip to content

Commit

Permalink
[Serializer] XmlEncoder: don't cast padded strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ogizanagi committed Jul 8, 2019
1 parent 5328c4b commit c1bfaa1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Expand Up @@ -303,7 +303,7 @@ private function parseXmlAttributes(\DOMNode $node, array $context = [])
$typeCastAttributes = $this->resolveXmlTypeCastAttributes($context);

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

continue;
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php
Expand Up @@ -306,6 +306,17 @@ public function testNoTypeCastAttribute()
$this->assertSame($expected, $data);
}

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

$data = $this->encoder->decode($source, 'xml');
$this->assertSame('018', $data['@a']);
}

public function testEncode()
{
$source = $this->getXmlSource();
Expand Down

0 comments on commit c1bfaa1

Please sign in to comment.