From 6498e0deb428bab135fdf50a3733ff50ae500bfe Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Thu, 27 Apr 2017 16:40:42 +0530 Subject: [PATCH 1/2] CRM-20171: avoid warning while loading external entity --- CRM/Case/Audit/AuditConfig.php | 5 ++++- CRM/Case/XMLRepository.php | 2 ++ CRM/Core/CodeGen/Util/Xml.php | 2 ++ CRM/Utils/Migrate/Import.php | 5 ++++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CRM/Case/Audit/AuditConfig.php b/CRM/Case/Audit/AuditConfig.php index 14bc772ff168..3fedba067845 100644 --- a/CRM/Case/Audit/AuditConfig.php +++ b/CRM/Case/Audit/AuditConfig.php @@ -61,7 +61,10 @@ public function loadConfig() { $this->includeRules = array(); $doc = new DOMDocument(); - if ($doc->load(dirname(__FILE__) . '/' . $this->filename)) { + $oldValue = libxml_disable_entity_loader(FALSE); + $load = $doc->load(dirname(__FILE__) . '/' . $this->filename); + libxml_disable_entity_loader($oldValue); + if ($load) { $regions = $doc->getElementsByTagName("region"); foreach ($regions as $region) { $regionName = $region->getAttribute("name"); diff --git a/CRM/Case/XMLRepository.php b/CRM/Case/XMLRepository.php index 89dcce5ce4af..34fc42da55db 100644 --- a/CRM/Case/XMLRepository.php +++ b/CRM/Case/XMLRepository.php @@ -136,7 +136,9 @@ public function retrieveFile($caseType) { if ($fileName && file_exists($fileName)) { // read xml file $dom = new DomDocument(); + $oldValue = libxml_disable_entity_loader(FALSE); $dom->load($fileName); + libxml_disable_entity_loader($oldValue); $dom->xinclude(); $fileXml = simplexml_import_dom($dom); } diff --git a/CRM/Core/CodeGen/Util/Xml.php b/CRM/Core/CodeGen/Util/Xml.php index 4711fdc472a2..aa3335581e97 100644 --- a/CRM/Core/CodeGen/Util/Xml.php +++ b/CRM/Core/CodeGen/Util/Xml.php @@ -11,8 +11,10 @@ class CRM_Core_CodeGen_Util_Xml { * @return SimpleXMLElement|bool */ public static function parse($file) { + $oldValue = libxml_disable_entity_loader(FALSE); $dom = new DomDocument(); $dom->load($file); + libxml_disable_entity_loader($oldValue); $dom->xinclude(); $xml = simplexml_import_dom($dom); return $xml; diff --git a/CRM/Utils/Migrate/Import.php b/CRM/Utils/Migrate/Import.php index 311fb4516d4e..29397a960fb4 100644 --- a/CRM/Utils/Migrate/Import.php +++ b/CRM/Utils/Migrate/Import.php @@ -48,7 +48,10 @@ public function __construct() { public function run($file) { // read xml file $dom = new DomDocument(); - if (!$dom->load($file)) { + $oldValue = libxml_disable_entity_loader(FALSE); + $load = $dom->load($file); + libxml_disable_entity_loader($oldValue); + if (!$load) { throw new CRM_Core_Exception("Failed to parse XML file \"$file\""); } $dom->xinclude(); From f9857c59f2c05c37229265d2142fdf8a06a0188b Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Tue, 2 May 2017 18:09:34 +0530 Subject: [PATCH 2/2] replace load with loadXML() --- CRM/Case/Audit/AuditConfig.php | 5 ++--- CRM/Case/XMLRepository.php | 6 +++--- CRM/Core/CodeGen/Util/Xml.php | 6 +++--- CRM/Utils/Migrate/Import.php | 5 ++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/CRM/Case/Audit/AuditConfig.php b/CRM/Case/Audit/AuditConfig.php index 3fedba067845..5065cca44b79 100644 --- a/CRM/Case/Audit/AuditConfig.php +++ b/CRM/Case/Audit/AuditConfig.php @@ -61,9 +61,8 @@ public function loadConfig() { $this->includeRules = array(); $doc = new DOMDocument(); - $oldValue = libxml_disable_entity_loader(FALSE); - $load = $doc->load(dirname(__FILE__) . '/' . $this->filename); - libxml_disable_entity_loader($oldValue); + $xmlString = file_get_contents(dirname(__FILE__) . '/' . $this->filename); + $load = $doc->loadXML($xmlString); if ($load) { $regions = $doc->getElementsByTagName("region"); foreach ($regions as $region) { diff --git a/CRM/Case/XMLRepository.php b/CRM/Case/XMLRepository.php index 34fc42da55db..bf6e2c210b3a 100644 --- a/CRM/Case/XMLRepository.php +++ b/CRM/Case/XMLRepository.php @@ -136,9 +136,9 @@ public function retrieveFile($caseType) { if ($fileName && file_exists($fileName)) { // read xml file $dom = new DomDocument(); - $oldValue = libxml_disable_entity_loader(FALSE); - $dom->load($fileName); - libxml_disable_entity_loader($oldValue); + $xmlString = file_get_contents($fileName); + $dom->loadXML($xmlString); + $dom->documentURI = $fileName; $dom->xinclude(); $fileXml = simplexml_import_dom($dom); } diff --git a/CRM/Core/CodeGen/Util/Xml.php b/CRM/Core/CodeGen/Util/Xml.php index aa3335581e97..96f94477e9a6 100644 --- a/CRM/Core/CodeGen/Util/Xml.php +++ b/CRM/Core/CodeGen/Util/Xml.php @@ -11,10 +11,10 @@ class CRM_Core_CodeGen_Util_Xml { * @return SimpleXMLElement|bool */ public static function parse($file) { - $oldValue = libxml_disable_entity_loader(FALSE); $dom = new DomDocument(); - $dom->load($file); - libxml_disable_entity_loader($oldValue); + $xmlString = file_get_contents($file); + $dom->loadXML($xmlString); + $dom->documentURI = $file; $dom->xinclude(); $xml = simplexml_import_dom($dom); return $xml; diff --git a/CRM/Utils/Migrate/Import.php b/CRM/Utils/Migrate/Import.php index 29397a960fb4..d79059590151 100644 --- a/CRM/Utils/Migrate/Import.php +++ b/CRM/Utils/Migrate/Import.php @@ -48,9 +48,8 @@ public function __construct() { public function run($file) { // read xml file $dom = new DomDocument(); - $oldValue = libxml_disable_entity_loader(FALSE); - $load = $dom->load($file); - libxml_disable_entity_loader($oldValue); + $xmlString = file_get_contents($file); + $load = $dom->loadXML($xmlString); if (!$load) { throw new CRM_Core_Exception("Failed to parse XML file \"$file\""); }