Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Ignore processing instructions #22005

Copy link
Copy link
Closed
@greg0ire

Description

@greg0ire
Issue body actions
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);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.