Skip to content

Commit 6d31e3b

Browse files
committed
Fix crash in verifyproblem when in or ans files are not utf-8
1 parent 449d853 commit 6d31e3b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

problemtools/verifyproblem.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,13 @@ def __init__(self, problem, base, testcasegroup):
142142
problem.testcase_by_infile[self.infile] = self
143143

144144
def check_newlines(self, filename):
145-
with open(filename, 'r') as f:
146-
data = f.read()
145+
with open(filename, 'rb') as f:
146+
rawdata = f.read()
147+
try:
148+
data = rawdata.decode('utf-8', 'strict')
149+
except UnicodeDecodeError:
150+
self.warning(f'The file {filename} could not be decoded as utf-8')
151+
return
147152
if data.find('\r') != -1:
148153
self.warning(f'The file {filename} contains non-standard line breaks.')
149154
if len(data) > 0 and data[-1] != '\n':

0 commit comments

Comments
 (0)