Merge pull request #10034 from cakephp/issue-10031

Add support for the parseHuge option.
This commit is contained in:
José Lorenzo Rodríguez 2017-01-15 11:19:52 +01:00 committed by GitHub
commit 541fb03438
2 changed files with 21 additions and 2 deletions

View file

@ -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 = '<tag>value</tag>';
$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.
*

View file

@ -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);