Skip to content

Commit

Permalink
Catch AttributeError on escapte_as_utf8 function
Browse files Browse the repository at this point in the history
  • Loading branch information
xoriole committed Jan 22, 2024
1 parent 94dfae1 commit 696cd9c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/tribler/core/components/libtorrent/torrentdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from tribler.core.utilities.utilities import bdecode_compat, is_valid_url


def escape_as_utf8(string, encoding='utf8') -> str:
def escape_as_utf8(string: str, encoding: str ='utf8') -> str:
"""
Make a string UTF-8 compliant, destroying characters if necessary.
Expand All @@ -36,12 +36,12 @@ def escape_as_utf8(string, encoding='utf8') -> str:
# Try seeing if the delivered encoding is correct and we
# can convert to utf8 without any issues.
return string.decode(encoding).encode('utf8').decode('utf8')
except (LookupError, TypeError, ValueError):
except (LookupError, TypeError, ValueError, AttributeError):
try:
# The delivered encoding is incorrect, cast it to
# latin1 and hope for the best (minor corruption).
return string.decode('latin1').encode('utf8', 'ignore').decode('utf8')
except (TypeError, ValueError):
except (TypeError, ValueError, AttributeError):
# This is a very nasty string (e.g. '\u266b'), remove the illegal entries.
return string.encode('utf8', 'ignore').decode('utf8')

Expand Down

0 comments on commit 696cd9c

Please sign in to comment.