From d63d63560b619132dba052635db7bded58d87341 Mon Sep 17 00:00:00 2001 From: Alexey Avramov Date: Sat, 3 Feb 2024 22:12:47 +0900 Subject: [PATCH] Sanitize comments: prevent UnicodeDecodeError in some cases --- tird/tird.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tird/tird.py b/tird/tird.py index 7a16f4d..94aa152 100755 --- a/tird/tird.py +++ b/tird/tird.py @@ -446,6 +446,9 @@ def get_comments_bytes() -> bytes: f'{BOL}[10] Comments (optional, up to {COMMENTS_SIZE} B):{RES} ') if comments != '': + # Sanitize comments: prevent UnicodeDecodeError in some cases + comments = comments.encode()[:COMMENTS_SIZE].decode('utf-8', 'ignore') + comments_bytes: bytes = comments.encode() comments_bytes = b''.join([ comments_bytes,