File tree 2 files changed +33
-2
lines changed
Filter options
src/Symfony/Component/Serializer
2 files changed +33
-2
lines changed
Original file line number Diff line number Diff line change @@ -92,14 +92,16 @@ public function decode($data, $format, array $context = array())
92
92
throw new UnexpectedValueException ($ error ->message );
93
93
}
94
94
95
+ $ rootNode = null ;
95
96
foreach ($ dom ->childNodes as $ child ) {
96
97
if ($ child ->nodeType === XML_DOCUMENT_TYPE_NODE ) {
97
98
throw new UnexpectedValueException ('Document types are not allowed. ' );
98
99
}
100
+ if (!$ rootNode && $ child ->nodeType !== XML_PI_NODE ) {
101
+ $ rootNode = $ child ;
102
+ }
99
103
}
100
104
101
- $ rootNode = $ dom ->firstChild ;
102
-
103
105
// todo: throw an exception if the root node name is not correctly configured (bc)
104
106
105
107
if ($ rootNode ->hasChildNodes ()) {
@@ -329,6 +331,10 @@ private function parseXmlValue(\DOMNode $node)
329
331
$ value = array ();
330
332
331
333
foreach ($ node ->childNodes as $ subnode ) {
334
+ if ($ subnode ->nodeType === XML_PI_NODE ) {
335
+ continue ;
336
+ }
337
+
332
338
$ val = $ this ->parseXml ($ subnode );
333
339
334
340
if ('item ' === $ subnode ->nodeName && isset ($ val ['@key ' ])) {
Original file line number Diff line number Diff line change @@ -371,6 +371,14 @@ public function testDecodeArray()
371
371
$ this ->assertEquals ($ expected , $ this ->encoder ->decode ($ source , 'xml ' ));
372
372
}
373
373
374
+ public function testDecodeXMLWithProcessInstruction ()
375
+ {
376
+ $ source = $ this ->getXmlPISource ();
377
+ $ obj = $ this ->getObject ();
378
+
379
+ $ this ->assertEquals (get_object_vars ($ obj ), $ this ->encoder ->decode ($ source , 'xml ' ));
380
+ }
381
+
374
382
public function testDecodeIgnoreWhiteSpace ()
375
383
{
376
384
$ source = <<<'XML'
@@ -465,6 +473,23 @@ public function testDecodeEmptyXml()
465
473
$ this ->encoder ->decode (' ' , 'xml ' );
466
474
}
467
475
476
+ protected function getXmlPISource ()
477
+ {
478
+ return '<?xml version="1.0"?> ' ."\n" .
479
+ '<?xml-stylesheet type="text/xsl" href="/xsl/xmlverbatimwrapper.xsl"?> ' .
480
+ '<?display table-view?> ' .
481
+ '<?sort alpha-ascending?> ' .
482
+ '<response> ' .
483
+ '<foo>foo</foo> ' .
484
+ '<?textinfo whitespace is allowed ?> ' .
485
+ '<bar>a</bar><bar>b</bar> ' .
486
+ '<baz><key>val</key><key2>val</key2><item key="A B">bar</item> ' .
487
+ '<item><title>title1</title></item><?item ignore-title ?><item><title>title2</title></item> ' .
488
+ '<Barry><FooBar id="1"><Baz>Ed</Baz></FooBar></Barry></baz> ' .
489
+ '<qux>1</qux> ' .
490
+ '</response><?instrtuction <value> ?> ' ."\n" ;
491
+ }
492
+
468
493
protected function getXmlSource ()
469
494
{
470
495
return '<?xml version="1.0"?> ' ."\n" .
You can’t perform that action at this time.
0 commit comments