diff --git a/filemanager/filemanager.py b/filemanager/filemanager.py index 9fff1f51f..ab7541a9f 100644 --- a/filemanager/filemanager.py +++ b/filemanager/filemanager.py @@ -716,7 +716,9 @@ class FileManager: if self.data['fileName'].find(pathCheck) == -1 or self.data['fileName'].find('..') > -1: return self.ajaxPre(0, 'Not allowed.') - command = 'cat ' + self.returnPathEnclosed(self.data['fileName']) + # Ensure proper UTF-8 handling for file reading + # Use explicit UTF-8 locale for the cat command + command = 'LANG=C.UTF-8 LC_ALL=C.UTF-8 cat ' + self.returnPathEnclosed(self.data['fileName']) finalData['fileContents'] = ProcessUtilities.outputExecutioner(command, website.externalApp) except: pathCheck = '/' @@ -724,12 +726,15 @@ class FileManager: if self.data['fileName'].find(pathCheck) == -1 or self.data['fileName'].find('..') > -1: return self.ajaxPre(0, 'Not allowed.') - command = 'cat ' + self.returnPathEnclosed(self.data['fileName']) + # Ensure proper UTF-8 handling for file reading + # Use explicit UTF-8 locale for the cat command + command = 'LANG=C.UTF-8 LC_ALL=C.UTF-8 cat ' + self.returnPathEnclosed(self.data['fileName']) finalData['fileContents'] = ProcessUtilities.outputExecutioner(command) - json_data = json.dumps(finalData) - return HttpResponse(json_data) + # Ensure proper UTF-8 encoding in JSON response + json_data = json.dumps(finalData, ensure_ascii=False) + return HttpResponse(json_data, content_type='application/json; charset=utf-8') except BaseException as msg: return self.ajaxPre(0, str(msg)) diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index 46cd51473..124c6b86f 100644 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -324,10 +324,15 @@ class ProcessUtilities(multi.Thread): if user!=None: if not command.startswith('sudo'): command = f'sudo -u {user} {command}' + # Ensure UTF-8 environment for proper character handling + env = os.environ.copy() + env['LC_ALL'] = 'en_US.UTF-8' + env['LANG'] = 'en_US.UTF-8' + if shell == None or shell == True: - p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) else: - p = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + p = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) if retRequired: return 1, p.communicate()[0].decode("utf-8")