Skip to content

Commit

Permalink
fix crash on downloading non utf-8 files
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelleas committed Jan 16, 2024
1 parent bd05031 commit f385c67
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions checkpy/downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,15 @@ def _extractFile(zipfile: zf.ZipFile, path: pathlib.Path, filePath: pathlib.Path
zipPathString = path.as_posix()
if filePath.is_file():
with zipfile.open(zipPathString) as new, open(str(filePath), "r") as existing:
# read file, decode, strip trailing whitespace, remove carrier return
newText = ''.join(new.read().decode('utf-8').strip().splitlines())
# read file and decode
try:
newText = new.read().decode('utf-8')
except UnicodeDecodeError:
# Skip any non utf-8 file
return

# strip trailing whitespace, remove carrier return
newText = ''.join(newText.strip().splitlines())
existingText = ''.join(existing.read().strip().splitlines())
if newText != existingText:
printer.displayUpdate(str(path))
Expand Down

0 comments on commit f385c67

Please sign in to comment.