From 55a7d194c2f48b4cb92de4337c913c32b7cb7806 Mon Sep 17 00:00:00 2001 From: Benjamin Altpeter Date: Mon, 7 Oct 2024 14:24:58 +0200 Subject: [PATCH] Fixes #4: Avoid UnicodeEncodeError (surrogates not allowed) --- datasette/plugins/long-cell.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datasette/plugins/long-cell.py b/datasette/plugins/long-cell.py index 0d9f688..8fe66eb 100644 --- a/datasette/plugins/long-cell.py +++ b/datasette/plugins/long-cell.py @@ -18,7 +18,7 @@ def is_human_readable_text(value): def as_base64(value): if isinstance(value, str): - return base64.b64encode(value.encode("utf-8")).decode("utf-8") + return base64.b64encode(value.encode("utf-8", "backslashreplace")).decode("utf-8") elif isinstance(value, bytes): return base64.b64encode(value).decode("utf-8") else: @@ -42,7 +42,7 @@ def render_cell(value, column, row): value = '' make_textarea = lambda v: Markup( - ''.format(escape(v)) + ''.format(escape(v).encode("utf-8", "backslashreplace").decode("utf-8")) ) if column in ("headers", "cookies") and value.startswith("[") and value.endswith("]"):