Closed
Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 2.8.18 |
Currently, when the Serializer is fed a piece of XML with a processing instruction, it will try to deserialize it instead of the real document below. It should just ignore it IMO.
Failing test case
<?php
namespace Whatever;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
class Foo
{
public $bar;
}
class FooTest extends TestCase
{
public function deserializationProvider()
{
return array(
'without PI' => array(
<<<'XML'
<?xml version='1.0' encoding='utf-8'?>
<foo>
<bar>hello</bar>
</foo>
XML
),
'with PI' => array(
<<<'XML'
<?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet type="text/xsl" href="/xsl/xmlverbatimwrapper.xsl"?>
<foo>
<bar>hello</bar>
</foo>
XML
)
);
}
/**
* @dataProvider deserializationProvider
*/
public function testDeserialization($xml)
{
$encoders = array(new XmlEncoder());
$normalizers = array(new ObjectNormalizer());
$serializer = new Serializer($normalizers, $encoders);
$foo = $serializer->deserialize(
$xml,
Foo::class,
'xml'
);
$this->assertSame('hello', $foo->bar);
}
}