From e834cb418bf9255ce3d17b5e20cc2c3164174ab6 Mon Sep 17 00:00:00 2001 From: HorstOeko Date: Sun, 15 Sep 2024 13:23:27 +0200 Subject: [PATCH] Fix warnings in loadFromXmlString, now throwing exceptions --- src/XmlDocumentReader.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/XmlDocumentReader.php b/src/XmlDocumentReader.php index d0fab7a..bc62b2b 100644 --- a/src/XmlDocumentReader.php +++ b/src/XmlDocumentReader.php @@ -97,7 +97,19 @@ public function loadFromXmlString(string $source): XmlDocumentReader */ public function loadFromXmlFile(string $filename): XmlDocumentReader { - $this->internalDomDocument->load($filename); + $prevUseInternalErrors = \libxml_use_internal_errors(true); + + try { + $this->internalDomDocument->load($filename); + if (libxml_get_last_error()) { + throw new RuntimeException("Invalid XML detected."); + } + } catch (Throwable $e) { + throw new RuntimeException("Invalid XML detected."); + } finally { + libxml_clear_errors(); + libxml_use_internal_errors($prevUseInternalErrors); + } $this->registerDomXPath(); $this->registerNamespacesInDomXPath();