ソースを参照

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 年 前
コミット
bbefe53ae9

+ 2 - 1
src/Utility/Xml.php

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

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

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