mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #10034 from cakephp/issue-10031
Add support for the parseHuge option.
This commit is contained in:
commit
541fb03438
2 changed files with 21 additions and 2 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue