diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 1cf8ee126f..6d256ff2ea 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -304,7 +304,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec $typeCastAttributes = $this->resolveXmlTypeCastAttributes($context); foreach ($node->attributes as $attr) { - if (!is_numeric($attr->nodeValue) || !$typeCastAttributes || (isset($attr->nodeValue[1]) && '0' === $attr->nodeValue[0])) { + if (!is_numeric($attr->nodeValue) || !$typeCastAttributes || (isset($attr->nodeValue[1]) && '0' === $attr->nodeValue[0] && '.' !== $attr->nodeValue[1])) { $data['@'.$attr->nodeName] = $attr->nodeValue; continue; diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php index 94f2e6c18a..c9b2de2e83 100644 --- a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php +++ b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php @@ -268,10 +268,10 @@ XML; { $source = << -Name +Name XML; - $this->assertSame(['@index' => -12.11, '#' => 'Name'], $this->encoder->decode($source, 'xml')); + $this->assertSame(['@index' => 12.11, '#' => 'Name'], $this->encoder->decode($source, 'xml')); } public function testDecodeNegativeFloatAttribute() @@ -284,6 +284,16 @@ XML; $this->assertSame(['@index' => -12.11, '#' => 'Name'], $this->encoder->decode($source, 'xml')); } + public function testDecodeFloatAttributeWithZeroWholeNumber() + { + $source = << +Name +XML; + + $this->assertSame(['@index' => 0.123, '#' => 'Name'], $this->encoder->decode($source, 'xml')); + } + public function testNoTypeCastAttribute() { $source = <<