Skip to content

Commit 883bb56

Browse files
committed
[Serializer] fixed bc-break with cdata-section nodes
1 parent d920521 commit 883bb56

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Encoder/XmlEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private function parseXmlValue(\DOMNode $node)
305305
return $node->nodeValue;
306306
}
307307

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

Tests/Encoder/XmlEncoderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ public function testDecode()
228228
$this->assertEquals(get_object_vars($obj), $this->encoder->decode($source, 'xml'));
229229
}
230230

231+
public function testDecodeCdataWrapping()
232+
{
233+
$expected = array(
234+
'firstname' => 'Paul <or Me>',
235+
);
236+
237+
$xml = '<?xml version="1.0"?>'."\n".
238+
'<response><firstname><![CDATA[Paul <or Me>]]></firstname></response>'."\n";
239+
240+
$this->assertEquals($expected, $this->encoder->decode($xml, 'xml'));
241+
}
242+
231243
public function testDecodeScalarWithAttribute()
232244
{
233245
$source = '<?xml version="1.0"?>'."\n".

0 commit comments

Comments
 (0)