Force UTF-8 encoding when processing diff text

pull/1031/head
dgtlmoon 2 years ago
parent 8d5b0b5576
commit d4b241720a

@ -816,9 +816,11 @@ def changedetection_app(config=None, datastore_o=None):
newest_file = history[dates[-1]] newest_file = history[dates[-1]]
# Read as binary and force decode as UTF-8
# Windows may fail decode in python if we just use 'r' mode (chardet decode exception)
try: try:
with open(newest_file, 'r') as f: with open(newest_file, 'rb') as f:
newest_version_file_contents = f.read() newest_version_file_contents = f.read().decode('utf-8')
except Exception as e: except Exception as e:
newest_version_file_contents = "Unable to read {}.\n".format(newest_file) newest_version_file_contents = "Unable to read {}.\n".format(newest_file)
@ -830,8 +832,8 @@ def changedetection_app(config=None, datastore_o=None):
previous_file = history[dates[-2]] previous_file = history[dates[-2]]
try: try:
with open(previous_file, 'r') as f: with open(previous_file, 'rb') as f:
previous_version_file_contents = f.read() previous_version_file_contents = f.read().decode('utf-8')
except Exception as e: except Exception as e:
previous_version_file_contents = "Unable to read {}.\n".format(previous_file) previous_version_file_contents = "Unable to read {}.\n".format(previous_file)

Loading…
Cancel
Save