Skip to content

Commit

Permalink
Merge pull request #10034 from cakephp/issue-10031
Browse files Browse the repository at this point in the history
Add support for the parseHuge option.
  • Loading branch information
lorenzo committed Jan 15, 2017
2 parents d40b39f + 273a8a2 commit 541fb03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/Cake/Test/Case/Utility/XmlTest.php
Expand Up @@ -167,6 +167,18 @@ public function testBuild() {
$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.
*
Expand Down
11 changes: 9 additions & 2 deletions lib/Cake/Utility/Xml.php
Expand Up @@ -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
Expand All @@ -94,7 +96,8 @@ public static function build($input, $options = array()) {
$defaults = array(
'return' => 'simplexml',
'loadEntities' => false,
'readFile' => true
'readFile' => true,
'parseHuge' => true
);
$options += $defaults;

Expand Down Expand Up @@ -135,6 +138,10 @@ protected static function _loadXml($input, $options) {
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);
Expand Down

0 comments on commit 541fb03

Please sign in to comment.