mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix super-nasty character decoding error.
This commit is contained in:
parent
bccea55bbb
commit
02091a0fa6
@ -1387,12 +1387,18 @@ class OEBBook(object):
|
|||||||
def decode(self, data):
|
def decode(self, data):
|
||||||
if isinstance(data, unicode):
|
if isinstance(data, unicode):
|
||||||
return data
|
return data
|
||||||
encodings = ['utf-8', 'utf-16']
|
if data[:2] in ('\xff\xfe', '\xfe\xff'):
|
||||||
if self.encoding is not None:
|
|
||||||
encodings.append(self.encoding)
|
|
||||||
for encoding in encodings:
|
|
||||||
try:
|
try:
|
||||||
return data.decode(encoding)
|
return data.decode('utf-16')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
return data.decode('utf-8')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
pass
|
||||||
|
if self.encoding is not None:
|
||||||
|
try:
|
||||||
|
return data.decode(self.encoding)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
pass
|
pass
|
||||||
data, _ = xml_to_unicode(data)
|
data, _ = xml_to_unicode(data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user