Skip to content

Commit 60c53c1

Browse files
committed
Merge branch '2.8' into 3.2
* 2.8: HttpCache: New test for revalidating responses with an expired TTL [Serializer] [XML] Ignore Process Instruction
2 parents ddc4390 + d1c3d68 commit 60c53c1

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

Encoder/XmlEncoder.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,16 @@ public function decode($data, $format, array $context = array())
9595
throw new UnexpectedValueException($error->message);
9696
}
9797

98+
$rootNode = null;
9899
foreach ($dom->childNodes as $child) {
99100
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
100101
throw new UnexpectedValueException('Document types are not allowed.');
101102
}
103+
if (!$rootNode && $child->nodeType !== XML_PI_NODE) {
104+
$rootNode = $child;
105+
}
102106
}
103107

104-
$rootNode = $dom->firstChild;
105-
106108
// todo: throw an exception if the root node name is not correctly configured (bc)
107109

108110
if ($rootNode->hasChildNodes()) {
@@ -332,6 +334,10 @@ private function parseXmlValue(\DOMNode $node)
332334
$value = array();
333335

334336
foreach ($node->childNodes as $subnode) {
337+
if ($subnode->nodeType === XML_PI_NODE) {
338+
continue;
339+
}
340+
335341
$val = $this->parseXml($subnode);
336342

337343
if ('item' === $subnode->nodeName && isset($val['@key'])) {

Tests/Encoder/XmlEncoderTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,44 @@ public function testDecodeArray()
370370
$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
371371
}
372372

373+
public function testDecodeXMLWithProcessInstruction()
374+
{
375+
$source = <<<'XML'
376+
<?xml version="1.0"?>
377+
<?xml-stylesheet type="text/xsl" href="/xsl/xmlverbatimwrapper.xsl"?>
378+
<?display table-view?>
379+
<?sort alpha-ascending?>
380+
<response>
381+
<foo>foo</foo>
382+
<?textinfo whitespace is allowed ?>
383+
<bar>a</bar>
384+
<bar>b</bar>
385+
<baz>
386+
<key>val</key>
387+
<key2>val</key2>
388+
<item key="A B">bar</item>
389+
<item>
390+
<title>title1</title>
391+
</item>
392+
<?item ignore-title ?>
393+
<item>
394+
<title>title2</title>
395+
</item>
396+
<Barry>
397+
<FooBar id="1">
398+
<Baz>Ed</Baz>
399+
</FooBar>
400+
</Barry>
401+
</baz>
402+
<qux>1</qux>
403+
</response>
404+
<?instruction <value> ?>
405+
XML;
406+
$obj = $this->getObject();
407+
408+
$this->assertEquals(get_object_vars($obj), $this->encoder->decode($source, 'xml'));
409+
}
410+
373411
public function testDecodeIgnoreWhiteSpace()
374412
{
375413
$source = <<<'XML'

0 commit comments

Comments
 (0)