From bd55096bbadafbd17a1c2c035345096cea93d8e5 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Thu, 4 Mar 2021 17:03:41 +0100 Subject: [PATCH] Propper handle libxml errors --- .../message/unfurl/UnfurlResponse.class.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/lib/system/message/unfurl/UnfurlResponse.class.php b/wcfsetup/install/files/lib/system/message/unfurl/UnfurlResponse.class.php index d26bbe21b5..7fdaa5908f 100644 --- a/wcfsetup/install/files/lib/system/message/unfurl/UnfurlResponse.class.php +++ b/wcfsetup/install/files/lib/system/message/unfurl/UnfurlResponse.class.php @@ -187,10 +187,19 @@ final class UnfurlResponse */ private function readDomDocument(): void { - \libxml_use_internal_errors(true); - $this->domDocument = new \DOMDocument(); - if (!$this->domDocument->loadHTML('' . $this->body)) { - throw new ParsingFailed("Could not parse body."); + $useInternalErrors = \libxml_use_internal_errors(true); + \libxml_clear_errors(); + try { + $this->domDocument = new \DOMDocument(); + if (!$this->domDocument->loadHTML('' . $this->body)) { + throw new ParsingFailed("DOMDocument::loadHTML() failed"); + } + foreach (\libxml_get_errors() as $error) { + throw new ParsingFailed("libxml error: {$error->message}.", $error->code); + } + } finally { + \libxml_use_internal_errors($useInternalErrors); + \libxml_clear_errors(); } } -- 2.20.1