Skip to content

Commit

Permalink
fix utf8 decoding bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-peugnet committed Dec 14, 2022
1 parent c88a099 commit 0e1f22f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/class/Servicerender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<?xml encoding="utf-8" ?>' . $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);
Expand Down

0 comments on commit 0e1f22f

Please sign in to comment.