Skip to content

Commit

Permalink
Report to Sentry, but display misencoded text (fixes DDCZ-2B)
Browse files Browse the repository at this point in the history
  • Loading branch information
Almad committed May 17, 2024
1 parent 0f3df80 commit 7f507df
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ddcz/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from django.utils.html import escape

from sentry_sdk import capture_exception


def create_slug(text):
slug = normalize("NFD", text)
Expand All @@ -20,7 +22,11 @@ def misencode(text):
Has to be used when querying database for data stored by original application,
represented by MisencodedChar/TextField.
"""
return text.encode("cp1250").decode("latin2")
try:
return text.encode("cp1250").decode("latin2")
except (UnicodeEncodeError, UnicodeDecodeError) as err:
capture_exception(err)
return text.encode("cp1250", "ignore").decode("latin2", "ignore")


def escape_user_input(text, newline_to_br=True):
Expand Down

0 comments on commit 7f507df

Please sign in to comment.