diff --git a/Encoder/XmlEncoder.php b/Encoder/XmlEncoder.php index 9e4902c7c..fe48a9372 100644 --- a/Encoder/XmlEncoder.php +++ b/Encoder/XmlEncoder.php @@ -301,7 +301,7 @@ private function parseXmlAttributes(\DOMNode $node, array $context = []): array $typeCastAttributes = (bool) ($context[self::TYPE_CAST_ATTRIBUTES] ?? $this->defaultContext[self::TYPE_CAST_ATTRIBUTES]); 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/Tests/Encoder/XmlEncoderTest.php b/Tests/Encoder/XmlEncoderTest.php index c1bb517ab..64e0673fa 100644 --- a/Tests/Encoder/XmlEncoderTest.php +++ b/Tests/Encoder/XmlEncoderTest.php @@ -276,10 +276,10 @@ public function testDecodeFloatAttribute() { $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() @@ -292,6 +292,16 @@ public function testDecodeNegativeFloatAttribute() $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 = <<