[serializer] fixed whitespace issue when decoding xml

This commit is contained in:
fieg 2014-06-04 12:17:52 +02:00
parent 0a177805bc
commit 466a3d70b7
2 changed files with 14 additions and 1 deletions

View File

@ -77,7 +77,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
libxml_clear_errors();
$dom = new \DOMDocument();
$dom->loadXML($data, LIBXML_NONET);
$dom->loadXML($data, LIBXML_NONET | LIBXML_NOBLANKS);
libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);

View File

@ -240,6 +240,19 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, $this->encoder->decode($xml, 'xml'));
}
public function testDecodeCdataWrappingAndWhitespace()
{
$expected = array(
'firstname' => 'Paul <or Me>',
);
$xml = '<?xml version="1.0"?>'."\n".
'<response><firstname>'."\n".
'<![CDATA[Paul <or Me>]]></firstname></response>'."\n";
$this->assertEquals($expected, $this->encoder->decode($xml, 'xml'));
}
public function testDecodeScalarWithAttribute()
{
$source = '<?xml version="1.0"?>'."\n".