Skip to content

Commit b0505b6

Browse files
committed
[serializer] fixed whitespace issue when decoding xml
1 parent 883bb56 commit b0505b6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Encoder/XmlEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function decode($data, $format, array $context = array())
7777
libxml_clear_errors();
7878

7979
$dom = new \DOMDocument();
80-
$dom->loadXML($data, LIBXML_NONET);
80+
$dom->loadXML($data, LIBXML_NONET | LIBXML_NOBLANKS);
8181

8282
libxml_use_internal_errors($internalErrors);
8383
libxml_disable_entity_loader($disableEntities);

Tests/Encoder/XmlEncoderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,19 @@ public function testDecodeCdataWrapping()
240240
$this->assertEquals($expected, $this->encoder->decode($xml, 'xml'));
241241
}
242242

243+
public function testDecodeCdataWrappingAndWhitespace()
244+
{
245+
$expected = array(
246+
'firstname' => 'Paul <or Me>',
247+
);
248+
249+
$xml = '<?xml version="1.0"?>'."\n".
250+
'<response><firstname>'."\n".
251+
'<![CDATA[Paul <or Me>]]></firstname></response>'."\n";
252+
253+
$this->assertEquals($expected, $this->encoder->decode($xml, 'xml'));
254+
}
255+
243256
public function testDecodeScalarWithAttribute()
244257
{
245258
$source = '<?xml version="1.0"?>'."\n".

0 commit comments

Comments
 (0)