Fixing issue where Xml would not read CDATA blocks.

This commit is contained in:
mark_story 2010-10-23 11:01:13 -04:00
parent d771239104
commit 7aaf7e6b68
2 changed files with 15 additions and 2 deletions

View file

@ -88,14 +88,14 @@ class Xml {
return self::fromArray((array)$input, $options);
} elseif (strpos($input, '<') !== false) {
if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
return new SimpleXMLElement($input);
return new SimpleXMLElement($input, LIBXML_NOCDATA);
}
$dom = new DOMDocument();
$dom->loadXML($input);
return $dom;
} elseif (file_exists($input) || strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) {
if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
return new SimpleXMLElement($input, null, true);
return new SimpleXMLElement($input, LIBXML_NOCDATA, true);
}
$dom = new DOMDocument();
$dom->load($input);

View file

@ -797,6 +797,19 @@ class XmlTest extends CakeTestCase {
$this->assertEqual(str_replace(array("\r", "\n"), '', $xmlResponse->asXML()), $expected);
}
/**
* test that CDATA blocks don't get screwed up by SimpleXml
*
* @return void
*/
function testCdata() {
$xml = '<' . '?xml version="1.0" encoding="UTF-8"?>' .
'<people><name><![CDATA[ Mark ]]></name></people>';
$result = Xml::build($xml);
$this->assertEquals(' Mark ', (string)$result->name);
}
/**
* data provider for toArray() failures
*