Skip to content

Commit 68a1309

Browse files
authored
Fix encoding detection on PHP 8.1
Also get rid of deprecated utf8_encode
1 parent 130abb7 commit 68a1309

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lib/DAV/StringUtil.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ public static function textMatch($haystack, $needle, $collation, $matchType = 'c
7777
*/
7878
public static function ensureUTF8($input)
7979
{
80-
$encoding = mb_detect_encoding($input, ['UTF-8', 'ISO-8859-1'], true);
81-
82-
if ('ISO-8859-1' === $encoding) {
83-
return utf8_encode($input);
80+
if (!mb_check_encoding($input, 'UTF-8') && mb_check_encoding($input, 'ISO-8859-1')) {
81+
return mb_convert_encoding($input, 'UTF-8', 'ISO-8859-1');
8482
} else {
8583
return $input;
8684
}

0 commit comments

Comments
 (0)