From: joshuaruesweg Date: Thu, 4 Mar 2021 16:03:41 +0000 (+0100) Subject: Propper handle libxml errors X-Git-Tag: 5.4.0_Alpha_1~146^2~36 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=bd55096bbadafbd17a1c2c035345096cea93d8e5;p=GitHub%2FWoltLab%2FWCF.git Propper handle libxml errors --- 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(); } }