[Serializer] XmlEncoder: don't cast padded strings

This commit is contained in:
Maxime Steinhausser 2019-07-08 16:06:09 +02:00
parent 5328c4b552
commit c1bfaa1de4
2 changed files with 12 additions and 1 deletions

View File

@ -303,7 +303,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
$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;

View File

@ -306,6 +306,17 @@ XML;
$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();