From 68a1309757e22c11722eeafb0dea1a3d5faa6843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <91878298+come-nc@users.noreply.github.com> Date: Tue, 14 Jun 2022 09:07:44 +0200 Subject: [PATCH] Fix encoding detection on PHP 8.1 Also get rid of deprecated utf8_encode --- lib/DAV/StringUtil.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/DAV/StringUtil.php b/lib/DAV/StringUtil.php index 13a4399e30..edfb7fa5c2 100644 --- a/lib/DAV/StringUtil.php +++ b/lib/DAV/StringUtil.php @@ -77,10 +77,8 @@ public static function textMatch($haystack, $needle, $collation, $matchType = 'c */ public static function ensureUTF8($input) { - $encoding = mb_detect_encoding($input, ['UTF-8', 'ISO-8859-1'], true); - - if ('ISO-8859-1' === $encoding) { - return utf8_encode($input); + if (!mb_check_encoding($input, 'UTF-8') && mb_check_encoding($input, 'ISO-8859-1')) { + return mb_convert_encoding($input, 'UTF-8', 'ISO-8859-1'); } else { return $input; }