fix: Avoid encoding issue with titles

pull/821/head
Raphaël Vinot 2023-10-26 00:05:50 +02:00
parent d6e664d7ca
commit 21965758f2
1 changed files with 5 additions and 1 deletions

View File

@ -400,7 +400,11 @@ class CapturesIndex(Mapping):
if har_files: if har_files:
try: try:
har = HarFile(har_files[0], uuid) 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['timestamp'] = har.initial_start_time
cache['redirects'] = json.dumps(tree.redirects) if tree else '' 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.' cache['user_agent'] = har.root_user_agent if har.root_user_agent else 'No User Agent.'