git » urraka » commit 12e9514

Make sure the titles are utf8-safe

author Alberto Bertogli
2014-07-20 22:55:39 UTC
committer Alberto Bertogli
2014-07-20 22:55:39 UTC
parent 24b2613a7d27869cc7ea83af8d46ead1fc9be826

Make sure the titles are utf8-safe

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

urraka.cgi +4 -2

diff --git a/urraka.cgi b/urraka.cgi
index 05340c5..8e87307 100755
--- a/urraka.cgi
+++ b/urraka.cgi
@@ -118,12 +118,14 @@ def get_mobi_title(fname):
         name_offset = mobi_hdr_offset + get_int(head, mobi_hdr_offset + 84)
         name_len = get_int(head, mobi_hdr_offset + 88)
 
-        return head[name_offset:name_offset + name_len]
+        title = head[name_offset:name_offset + name_len]
     except (IndexError, struct.error) as e:
         # As a fallback, palm databases have a title as the first 32 bytes;
         # it's usually a crippled book title.
         logging.debug('Error getting title for %r: %s', fname, e)
-        return head[:32].strip('\0')
+        title = head[:32].strip('\0')
+
+    return title.decode('utf8', errors = 'replace')
 
 
 #