Skip to content

Commit 196f5c7

Browse files
authored
About: Use BOM to decode UTF-16 changelog file (#3601)
If the Windows changelog text file (which is encoded UTF-16LE with a Byte Order Marker at the start) is explicitly opened as 'utf_16_le', the BOM will be left in the stream, which throws off the parsing of the first line. Using 'encoding="utf_16"' automatically filters out the BOM after using it to determine the file endianness.
1 parent cb81d4c commit 196f5c7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/windows/about.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self):
6868
changelog_path = os.path.join(info.PATH, 'settings', '%s.log' % project)
6969
if os.path.exists(changelog_path):
7070
# Attempt to open changelog with utf-8, and then utf-16-le (for unix / windows support)
71-
for encoding_name in ('utf-8', 'utf_16_le'):
71+
for encoding_name in ('utf_8', 'utf_16'):
7272
try:
7373
with codecs.open(changelog_path, 'r', encoding=encoding_name) as changelog_file:
7474
if changelog_file.read():
@@ -183,7 +183,7 @@ def __init__(self):
183183

184184
# Get list of developers
185185
developer_list = []
186-
with codecs.open(os.path.join(info.RESOURCES_PATH, 'contributors.json'), 'r', 'utf-8') as contributors_file:
186+
with codecs.open(os.path.join(info.RESOURCES_PATH, 'contributors.json'), 'r', 'utf_8') as contributors_file:
187187
developer_string = contributors_file.read()
188188
developer_list = json.loads(developer_string)
189189

@@ -214,7 +214,7 @@ def __init__(self):
214214

215215
# Get list of supporters
216216
supporter_list = []
217-
with codecs.open(os.path.join(info.RESOURCES_PATH, 'supporters.json'), 'r', 'utf-8') as supporter_file:
217+
with codecs.open(os.path.join(info.RESOURCES_PATH, 'supporters.json'), 'r', 'utf_8') as supporter_file:
218218
supporter_string = supporter_file.read()
219219
supporter_list = json.loads(supporter_string)
220220

@@ -259,7 +259,7 @@ def __init__(self):
259259
changelog_path = os.path.join(info.PATH, 'settings', 'openshot-qt.log')
260260
if os.path.exists(changelog_path):
261261
# Attempt to open changelog with utf-8, and then utf-16-le (for unix / windows support)
262-
for encoding_name in ('utf-8', 'utf_16_le'):
262+
for encoding_name in ('utf_8', 'utf_16'):
263263
try:
264264
with codecs.open(changelog_path, 'r', encoding=encoding_name) as changelog_file:
265265
for line in changelog_file:
@@ -279,7 +279,7 @@ def __init__(self):
279279
changelog_path = os.path.join(info.PATH, 'settings', 'libopenshot.log')
280280
if os.path.exists(changelog_path):
281281
# Attempt to open changelog with utf-8, and then utf-16-le (for unix / windows support)
282-
for encoding_name in ('utf-8', 'utf_16_le'):
282+
for encoding_name in ('utf_8', 'utf_16'):
283283
try:
284284
with codecs.open(changelog_path, 'r', encoding=encoding_name) as changelog_file:
285285
for line in changelog_file:
@@ -298,8 +298,10 @@ def __init__(self):
298298
changelog_list = []
299299
changelog_path = os.path.join(info.PATH, 'settings', 'libopenshot-audio.log')
300300
if os.path.exists(changelog_path):
301-
# Attempt to open changelog with utf-8, and then utf-16-le (for unix / windows support)
302-
for encoding_name in ('utf-8', 'utf_16_le'):
301+
# Attempt to support Linux- and Windows-encoded files by opening
302+
# changelog with utf-8, then utf-16 (endianness via the BOM, which
303+
# gets filtered out automatically by the decoder)
304+
for encoding_name in ('utf_8', 'utf_16'):
303305
try:
304306
with codecs.open(changelog_path, 'r', encoding=encoding_name) as changelog_file:
305307
for line in changelog_file:

0 commit comments

Comments
 (0)