diff --git a/lib/Cake/Test/Case/Utility/XmlTest.php b/lib/Cake/Test/Case/Utility/XmlTest.php index a33663f75..01b13eac6 100644 --- a/lib/Cake/Test/Case/Utility/XmlTest.php +++ b/lib/Cake/Test/Case/Utility/XmlTest.php @@ -167,6 +167,18 @@ class XmlTest extends CakeTestCase { $this->assertNotRegExp('/encoding/', $obj->saveXML()); } +/** + * test build() method with huge option + * + * @return void + */ + public function testBuildHuge() { + $xml = 'value'; + $obj = Xml::build($xml, array('parseHuge' => true)); + $this->assertEquals('tag', $obj->getName()); + $this->assertEquals('value', (string)$obj); + } + /** * Test that the readFile option disables local file parsing. * diff --git a/lib/Cake/Utility/Xml.php b/lib/Cake/Utility/Xml.php index f27fc1497..a5a6876e3 100644 --- a/lib/Cake/Utility/Xml.php +++ b/lib/Cake/Utility/Xml.php @@ -80,7 +80,9 @@ class Xml { * - `readFile` Set to false to disable file reading. This is important to disable when * putting user data into Xml::build(). If enabled local & remote files will be read if they exist. * Defaults to true for backwards compatibility reasons. - * - If using array as input, you can pass `options` from Xml::fromArray. + * - `parseHuge` Enable the `LIBXML_PARSEHUGE` + * + * If using array as input, you can pass `options` from Xml::fromArray. * * @param string|array $input XML string, a path to a file, a URL or an array * @param array $options The options to use @@ -94,7 +96,8 @@ class Xml { $defaults = array( 'return' => 'simplexml', 'loadEntities' => false, - 'readFile' => true + 'readFile' => true, + 'parseHuge' => true ); $options += $defaults; @@ -135,6 +138,10 @@ class Xml { if ($hasDisable && !$options['loadEntities']) { libxml_disable_entity_loader(true); } + $flags = LIBXML_NOCDATA; + if (!empty($options['parseHuge'])) { + $flags |= LIBXML_PARSEHUGE; + } try { if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') { $xml = new SimpleXMLElement($input, LIBXML_NOCDATA);