Skip to content

Commit

Permalink
Fixes #4: Avoid UnicodeEncodeError (surrogates not allowed)
Browse files Browse the repository at this point in the history
  • Loading branch information
baltpeter committed Oct 7, 2024
1 parent 9832133 commit 55a7d19
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions datasette/plugins/long-cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -42,7 +42,7 @@ def render_cell(value, column, row):
value = ''

make_textarea = lambda v: Markup(
'<textarea class="tweasel-long-cell" readonly>{}</textarea>'.format(escape(v))
'<textarea class="tweasel-long-cell" readonly>{}</textarea>'.format(escape(v).encode("utf-8", "backslashreplace").decode("utf-8"))
)

if column in ("headers", "cookies") and value.startswith("[") and value.endswith("]"):
Expand Down

0 comments on commit 55a7d19

Please sign in to comment.