Skip to content

Commit

Permalink
Merge pull request #251 from gkreitz/crash_on_non_utf8_io_files
Browse files Browse the repository at this point in the history
Fix crash in verifyproblem when in or ans files are not utf-8
  • Loading branch information
pehrsoderman authored Jan 25, 2024
2 parents a8fdc40 + 7fb6089 commit 75cd6f3
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 75cd6f3

Please sign in to comment.