Browse Source

Fix failing test.

Previously domdocument mode preserved CDATA blocks. Continue to do that
for domdocument mode and only strip cdata for SimpleXMLElement. This
could result in CDATA block showing up in data parsed by
RequestHandlerComponent but the toArray() conversion should clean those
up.

Refs #11818
Mark Story 8 years ago
parent
commit
bbefe53ae9

+ 2 - 1
src/Utility/Xml.php

@@ -145,12 +145,13 @@ class Xml
         if ($hasDisable && !$options['loadEntities']) {
             libxml_disable_entity_loader(true);
         }
-        $flags = LIBXML_NOCDATA;
+        $flags = 0;
         if (!empty($options['parseHuge'])) {
             $flags |= LIBXML_PARSEHUGE;
         }
         try {
             if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
+                $flags |= LIBXML_NOCDATA;
                 $xml = new SimpleXMLElement($input, $flags);
             } else {
                 $xml = new DOMDocument();

+ 1 - 1
tests/TestCase/Controller/Component/RequestHandlerComponentTest.php

@@ -592,7 +592,7 @@ XML;
 <?xml version="1.0" encoding="utf-8"?>
 <article>
     <id>1</id>
-    <title>first</title>
+    <title><![CDATA[first]]></title>
 </article>
 XML;
         $this->Controller->request = new ServerRequest(['input' => $xml]);