From 80852cc395a06775d935482b1ba4b314b60a1122 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 18 Jun 2022 00:19:18 +0200 Subject: [PATCH] specify encoding when reading text files --- files/__main__.py | 2 +- files/routes/admin.py | 6 +++--- files/routes/static.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index da7c2681f..4b2dd25a9 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -90,7 +90,7 @@ def before_request(): ua = g.agent.lower() - with open('site_settings.json', 'r') as f: + with open('site_settings.json', 'r', encoding='utf_8') as f: app.config['SETTINGS'] = json.load(f) if request.host != app.config["SERVER_NAME"]: return {"error":"Unauthorized host provided."}, 401 diff --git a/files/routes/admin.py b/files/routes/admin.py index d51d68aab..7cc5affa8 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -494,10 +494,10 @@ def admin_git_head(): # Also, a malicious branch name would mean someone already owned the server # or repo, so I think this isn't a weak link. try: - with open('.git/HEAD') as head_f: + with open('.git/HEAD', encoding='utf_8') as head_f: head_txt = head_f.read() head_path = re.match('ref: (refs/.+)', head_txt).group(1) - with open('.git/' + head_path) as ref_f: + with open('.git/' + head_path, encoding='utf_8') as ref_f: gitref = ref_f.read()[0:short_len] except: return '' @@ -508,7 +508,7 @@ def admin_git_head(): def change_settings(v, setting): site_settings = app.config['SETTINGS'] site_settings[setting] = not site_settings[setting] - with open("site_settings.json", "w") as f: + with open("site_settings.json", "w", encoding='utf_8') as f: json.dump(site_settings, f) if site_settings[setting]: word = 'enable' diff --git a/files/routes/static.py b/files/routes/static.py index 14e252928..6c7bec32a 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -372,7 +372,7 @@ def settings_security(v): @app.get("/.well-known/assetlinks.json") def googleplayapp(): - with open("files/assets/assetlinks.json", "r") as f: + with open("files/assets/assetlinks.json", "r", encoding='utf_8') as f: return Response(f.read(), mimetype='application/json')