bug #22044 [Serializer] [XML] Ignore Process Instruction (jordscream)
This PR was merged into the 2.7 branch.
Discussion
----------
[Serializer] [XML] Ignore Process Instruction
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #22005
| License | MIT
| Doc PR | N/A
This Pull request ignores Process instruction data in XML for decoding the data.
Commits
-------
0c741f5704
[Serializer] [XML] Ignore Process Instruction
This commit is contained in:
commit
bca4778ef1
@ -92,14 +92,16 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
||||
throw new UnexpectedValueException($error->message);
|
||||
}
|
||||
|
||||
$rootNode = null;
|
||||
foreach ($dom->childNodes as $child) {
|
||||
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
|
||||
throw new UnexpectedValueException('Document types are not allowed.');
|
||||
}
|
||||
if (!$rootNode && $child->nodeType !== XML_PI_NODE) {
|
||||
$rootNode = $child;
|
||||
}
|
||||
}
|
||||
|
||||
$rootNode = $dom->firstChild;
|
||||
|
||||
// todo: throw an exception if the root node name is not correctly configured (bc)
|
||||
|
||||
if ($rootNode->hasChildNodes()) {
|
||||
@ -329,6 +331,10 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
||||
$value = array();
|
||||
|
||||
foreach ($node->childNodes as $subnode) {
|
||||
if ($subnode->nodeType === XML_PI_NODE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$val = $this->parseXml($subnode);
|
||||
|
||||
if ('item' === $subnode->nodeName && isset($val['@key'])) {
|
||||
|
@ -370,6 +370,44 @@ XML;
|
||||
$this->assertEquals($expected, $this->encoder->decode($source, 'xml'));
|
||||
}
|
||||
|
||||
public function testDecodeXMLWithProcessInstruction()
|
||||
{
|
||||
$source = <<<'XML'
|
||||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet type="text/xsl" href="/xsl/xmlverbatimwrapper.xsl"?>
|
||||
<?display table-view?>
|
||||
<?sort alpha-ascending?>
|
||||
<response>
|
||||
<foo>foo</foo>
|
||||
<?textinfo whitespace is allowed ?>
|
||||
<bar>a</bar>
|
||||
<bar>b</bar>
|
||||
<baz>
|
||||
<key>val</key>
|
||||
<key2>val</key2>
|
||||
<item key="A B">bar</item>
|
||||
<item>
|
||||
<title>title1</title>
|
||||
</item>
|
||||
<?item ignore-title ?>
|
||||
<item>
|
||||
<title>title2</title>
|
||||
</item>
|
||||
<Barry>
|
||||
<FooBar id="1">
|
||||
<Baz>Ed</Baz>
|
||||
</FooBar>
|
||||
</Barry>
|
||||
</baz>
|
||||
<qux>1</qux>
|
||||
</response>
|
||||
<?instruction <value> ?>
|
||||
XML;
|
||||
$obj = $this->getObject();
|
||||
|
||||
$this->assertEquals(get_object_vars($obj), $this->encoder->decode($source, 'xml'));
|
||||
}
|
||||
|
||||
public function testDecodeIgnoreWhiteSpace()
|
||||
{
|
||||
$source = <<<'XML'
|
||||
|
Reference in New Issue
Block a user