Skip to content

Commit

Permalink
Fix crash in verifyproblem when in or ans files are not utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
gkreitz committed Jan 25, 2024
1 parent a8fdc40 commit 7fb6089
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions problemtools/verifyproblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,13 @@ def __init__(self, problem: Problem, base: str, testcasegroup: TestCaseGroup):
problem.testcase_by_infile[self.infile] = self

def check_newlines(self, filename: str) -> None:
with open(filename, 'r') as f:
data = f.read()
with open(filename, 'rb') as f:
rawdata = f.read()
try:
data = rawdata.decode('utf-8', 'strict')
except UnicodeDecodeError:
self.warning(f'The file {filename} could not be decoded as utf-8')
return
if data.find('\r') != -1:
self.warning(f'The file {filename} contains non-standard line breaks.')
if len(data) > 0 and data[-1] != '\n':
Expand Down

0 comments on commit 7fb6089

Please sign in to comment.