8000 [Serializer] Ignore comments when decoding XML by q0rban · Pull Request #26445 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Ignore comments when decoding XML #26445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Prev Previous commit
Next Next commit
[Serializer] Test that decoding XML comments is possible
  • Loading branch information
James Sansbury committed Mar 7, 2018
commit 01ae25fe3f8d6a59abce39c27fb0e42a7dc36252
29 changes: 29 additions & 0 deletions src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,35 @@ public function testDecodeIgnoreComments()
$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
}

public function testDecodePreserveComments()
{
$source = <<<'XML'
<?xml version="1.0"?>
<people>
<person>
<!-- This comment should be decoded. -->
<firstname>Benjamin</firstname>
<lastname>Alexandre</lastname>
</person>
<person>
<firstname>Damien</firstname>
<lastname>Clay</lastname>
</person>
</people>
XML;

$this->encoder = new XmlEncoder('people', null, array(XML_PI_NODE));
$serializer = new Serializer(array(new CustomNormalizer()), array('xml' => new XmlEncoder()));
$this->encoder->setSerializer($serializer);

$expected = array('person' => array(
array('firstname' => 'Benjamin', 'lastname' => 'Alexandre', '#comment' => ' This comment should be decoded. '),
array('firstname' => 'Damien', 'lastname' => 'Clay'),
));

$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
}

public function testDecodeAlwaysAsCollection()
{
$this->encoder = new XmlEncoder('response', null);
Expand Down
0