From dd725466e5c28ad3e2d0872558571ae77e7931b0 Mon Sep 17 00:00:00 2001 From: Phuoc Dinh Le <47278241+cuom1999@users.noreply.github.com> Date: Wed, 31 Mar 2021 21:46:42 -0500 Subject: [PATCH] Another attempt to fix VNese bugs with utf-8. --- judge/views/submission.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/judge/views/submission.py b/judge/views/submission.py index 4e278ac..6c7d9e6 100644 --- a/judge/views/submission.py +++ b/judge/views/submission.py @@ -139,7 +139,16 @@ def group_test_cases(cases): def read_head_archive(archive, file): with archive.open(file) as f: - return f.read(settings.TESTCASE_VISIBLE_LENGTH + 3) + s = f.read(settings.TESTCASE_VISIBLE_LENGTH + 3) + # add this so there are no characters left behind (ex, 'รก' = 2 utf-8 chars) + while True: + try: + s.decode('utf-8') + break + except UnicodeDecodeError: + s += f.read(1) + return s + def get_visible_content(data): data = data or b''