From f385c670761bef7d3ae8eeaa749bd783dff81336 Mon Sep 17 00:00:00 2001 From: jelleas Date: Tue, 16 Jan 2024 14:39:36 +0100 Subject: [PATCH] fix crash on downloading non utf-8 files --- checkpy/downloader/downloader.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/checkpy/downloader/downloader.py b/checkpy/downloader/downloader.py index b72f33d..cdeb3de 100644 --- a/checkpy/downloader/downloader.py +++ b/checkpy/downloader/downloader.py @@ -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))