From c91bf1d66ae4adff9db9a3c7349d4f4ce4723d7d Mon Sep 17 00:00:00 2001
From: Isabel <isabel-andrea.uffinger@stud.hs-hannover.de>
Date: Tue, 12 Mar 2024 16:52:53 +0100
Subject: [PATCH] check encoding of attached files and convert to utf-8

---
 locallib.php | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/locallib.php b/locallib.php
index 4a1df0d..7d6ea83 100644
--- a/locallib.php
+++ b/locallib.php
@@ -294,19 +294,18 @@ function get_text_content_from_file($usercontext, $draftareaid, $keepfilename, $
     // TODO: make sure the mimetype is plain text
     // even task.xmls may contain mistakes (eg PDF )
 
-    //check if encoding of attached ist utf-8 else convert
+    //check if encoding of attached file is utf-8 else convert
     $content = $file->get_content();
-    if($encoding!==false){
+    if($encoding!=null){
         $enc=$encoding;
     } else {
-        $enc = mb_detect_encoding($content, mb_detect_order(), true);
+        $enc = mb_detect_encoding($content, null, true);
         if($enc===false){
             throw new invalid_parameter_exception('Encoding of attached file ' . $filepath . $filename . 'could\'nt be detectet.');
         }
     }
-    $content = mb_convert_encoding($content, $enc, 'UTF-8');
     if($enc!=='UTF-8'){
-        $content = mb_convert_encoding($content, 'UTF-8', $enc);
+        $content = mb_convert_encoding($content, 'UTF-8', $enc);        
     }
 
     return $content;
-- 
GitLab