[Serializer] fixed bc-break with cdata-section nodes

This commit is contained in:
fieg 2014-06-03 12:14:49 +02:00
parent 9c60a8582e
commit 48d9f36ea0
2 changed files with 13 additions and 1 deletions

View File

@ -305,7 +305,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
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;
}

View File

@ -228,6 +228,18 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase
$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".