Skip to content

Commit

Permalink
[Serializer] fixed bc-break with cdata-section nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
fieg committed Jun 3, 2014
1 parent 9c60a85 commit 48d9f36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Expand Up @@ -305,7 +305,7 @@ private function parseXmlValue(\DOMNode $node)
return $node->nodeValue;
}

if (1 === $node->childNodes->length && XML_TEXT_NODE === $node->firstChild->nodeType) {
if (1 === $node->childNodes->length && in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) {
return $node->firstChild->nodeValue;
}

Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php
Expand Up @@ -228,6 +228,18 @@ public function testDecode()
$this->assertEquals(get_object_vars($obj), $this->encoder->decode($source, 'xml'));
}

public function testDecodeCdataWrapping()
{
$expected = array(
'firstname' => 'Paul <or Me>',
);

$xml = '<?xml version="1.0"?>'."\n".
'<response><firstname><![CDATA[Paul <or Me>]]></firstname></response>'."\n";

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

public function testDecodeScalarWithAttribute()
{
$source = '<?xml version="1.0"?>'."\n".
Expand Down

0 comments on commit 48d9f36

Please sign in to comment.