From 21965758f265974e4a9cd68ffafd71476436d4c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 26 Oct 2023 00:05:50 +0200 Subject: [PATCH] fix: Avoid encoding issue with titles --- lookyloo/capturecache.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lookyloo/capturecache.py b/lookyloo/capturecache.py index c45cd277..81cab9ca 100644 --- a/lookyloo/capturecache.py +++ b/lookyloo/capturecache.py @@ -400,7 +400,11 @@ class CapturesIndex(Mapping): if har_files: try: har = HarFile(har_files[0], uuid) - cache['title'] = har.initial_title + try: + # If encoding fails, the cache cannot be stored in redis and it barfs. + cache['title'] = har.initial_title.encode().decode() + except UnicodeEncodeError: + cache['title'] = har.initial_title.encode('utf-8', 'backslashreplace').decode() cache['timestamp'] = har.initial_start_time cache['redirects'] = json.dumps(tree.redirects) if tree else '' cache['user_agent'] = har.root_user_agent if har.root_user_agent else 'No User Agent.'