]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
python: Handle incorrect utf-8 decodes.
authorE.Smith <31170571+azlm8t@users.noreply.github.com>
Tue, 25 Sep 2018 11:50:57 +0000 (12:50 +0100)
committerperexg <perex@perex.cz>
Wed, 26 Sep 2018 15:31:44 +0000 (17:31 +0200)
Some broadcasts can have different charsets (such as iso-8859-1) but
we assume utf-8 unless user has set it correctly. So when decode fails
we get an exception.  So we now attempt to decode with error
replacement so user sees incorrect character.

This gives "u'Denise Th\ufffd\ufffd':" as the string returned instead
when the received name contains an é that is in iso-8859-1 instead of
utf-8.

lib/py/tvh/htsmsg.py

index a5ea8ca36f6d8eac60ed561dee324ab51abbd799..8fe85d6504f0f9c68ddeefa7db84a2d880a07c2c 100644 (file)
@@ -179,7 +179,7 @@ def deserialize0(data, typ=HMF_MAP):
             try:
                 item = data[:dlen].decode('utf-8')
             except:
-                item = data[:dlen]
+                item = data[:dlen].decode(errors='replace')
         elif typ == HMF_BIN:
             item = HMFBin(data[:dlen])
         elif typ == HMF_S64:
@@ -201,7 +201,11 @@ def deserialize0(data, typ=HMF_MAP):
         if islist:
             msg.append(item)
         else:
-            msg[name.decode()] = item
+            try:
+                n = name.decode(errors="replace")
+            except:
+                n = name
+            msg[n] = item
         data = data[dlen:]
     return msg