From ec700890c0484250edb4796b197d490df99daa42 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 12 Nov 2015 17:20:17 +0100 Subject: update picofeed --- .../lib/PicoFeed/Parser/XmlEntityException.php | 12 +++ .../picofeed/lib/PicoFeed/Parser/XmlParser.php | 108 ++++++--------------- 2 files changed, 41 insertions(+), 79 deletions(-) create mode 100644 vendor/fguillot/picofeed/lib/PicoFeed/Parser/XmlEntityException.php (limited to 'vendor/fguillot/picofeed/lib/PicoFeed/Parser') diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/XmlEntityException.php b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/XmlEntityException.php new file mode 100644 index 000000000..f3f914d52 --- /dev/null +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/XmlEntityException.php @@ -0,0 +1,12 @@ +childNodes as $child) { - if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) { - if ($child->entities->length > 0) { - return false; - } - } - } - - if ($isRunningFpm === false) { - libxml_disable_entity_loader($entityLoaderDisabled); - } - - return $dom; + return self::scan($input); } /** @@ -101,12 +46,7 @@ class XmlParser return false; } - $dom = self::scanInput($input, function ($in) { - $dom = new DomDocument(); - $dom->loadXml($in, LIBXML_NONET); - - return $dom; - }); + $dom = self::scan($input, new DOMDocument()); // The document is empty, there is probably some parsing errors if ($dom && $dom->childNodes->length === 0) { @@ -116,6 +56,22 @@ class XmlParser return $dom; } + /** + * Small wrapper around ZendXml to turn their exceptions into picoFeed + * exceptions + * @param $input the xml to load + * @param $dom pass in a dom document or use null/omit if simpleXml should + * be used + */ + private static function scan($input, $dom=null) + { + try { + return Security::scan($input, $dom); + } catch(\ZendXml\Exception\RuntimeException $e) { + throw new XmlEntityException($e->getMessage()); + } + } + /** * Load HTML document by using a DomDocument instance or return false on failure. * @@ -127,27 +83,21 @@ class XmlParser */ public static function getHtmlDocument($input) { + $dom = new DomDocument(); + if (empty($input)) { - return new DomDocument(); + return $dom; } - if (version_compare(PHP_VERSION, '5.4.0', '>=')) { - $callback = function ($in) { - $dom = new DomDocument(); - $dom->loadHTML($in, LIBXML_NONET); + libxml_use_internal_errors(true); - return $dom; - }; + if (version_compare(PHP_VERSION, '5.4.0', '>=')) { + $dom->loadHTML($input, LIBXML_NONET); } else { - $callback = function ($in) { - $dom = new DomDocument(); - $dom->loadHTML($in); - - return $dom; - }; + $dom->loadHTML($input); } - return self::scanInput($input, $callback); + return $dom; } /** -- cgit v1.2.3