From 0e1f22fa9af690c6e1f469d32752e6bf2fc4f70d Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 14 Dec 2022 18:34:33 +0100 Subject: [PATCH] fix utf8 decoding bug --- app/class/Servicerender.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/class/Servicerender.php b/app/class/Servicerender.php index 270d83ce..57fb5083 100644 --- a/app/class/Servicerender.php +++ b/app/class/Servicerender.php @@ -446,9 +446,12 @@ private function autourl($text): string */ private function htmlink(string $text): string { - $dom = new DOMDocument(); + $dom = new DOMDocument('1.0', 'UTF-8'); + /** Force UTF-8 encoding for loadHTML by defining it in the content itself with an XML tag that need to be removed later */ + $text = '' . $text; /** @phpstan-ignore-next-line Error supposed to be thrown here but is'nt */ - $dom->loadHTML($text, LIBXML_NOERROR + LIBXML_HTML_NODEFDTD + LIBXML_HTML_NOIMPLIED); + $dom->loadHTML($text, LIBXML_NOERROR | LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); + $dom->removeChild($dom->firstChild); $links = $dom->getElementsByTagName('a'); foreach ($links as $link) { assert($link instanceof DOMElement);