[Serializer] XmlEncoder: don't cast padded strings
This commit is contained in:
parent
5328c4b552
commit
c1bfaa1de4
@ -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;
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user