Skip to content

Commit

Permalink
Merge pull request #5 from tweaselORG/b_long-cell-encoding
Browse files Browse the repository at this point in the history
Fixes #4: Avoid UnicodeEncodeError (surrogates not allowed)
  • Loading branch information
zner0L authored Oct 7, 2024
2 parents 9832133 + 55a7d19 commit 21ba2dc
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 21ba2dc

Please sign in to comment.