Skip to content
Permalink
Browse files

Port `parseHuge` option to 3.x

Refs #10034
  • Loading branch information...
markstory committed Jan 16, 2017
1 parent fa88503 commit 8aec91ed6549c0554516a7661d819e3683b7efee
Showing with 23 additions and 3 deletions.
  1. +10 −3 src/Utility/Xml.php
  2. +13 −0 tests/TestCase/Utility/XmlTest.php
@@ -92,7 +92,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 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` flag.
*
* 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 string|array $options The options to use
@@ -104,7 +106,8 @@ public static function build($input, array $options = [])
$defaults = [
'return' => 'simplexml',
'loadEntities' => false,
'readFile' => true
'readFile' => true,
'parseHuge' => true,
];
$options += $defaults;
@@ -142,9 +145,13 @@ 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);
$xml = new SimpleXMLElement($input, $flags);
} else {
$xml = new DOMDocument();
$xml->loadXML($input);
@@ -113,6 +113,19 @@ 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.
*

0 comments on commit 8aec91e

Please sign in to comment.
You can’t perform that action at this time.