mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-30 23:00:21 -04:00
Ensure encoding to JSON in BookList never blows up because of non UTF-8 bytestrings
This commit is contained in:
parent
48f8a9c338
commit
b172b84119
@ -11,7 +11,8 @@ import time
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
from calibre.devices.mime import mime_type_ext
|
||||
from calibre.devices.interface import BookList as _BookList
|
||||
from calibre.constants import filesystem_encoding
|
||||
from calibre.constants import filesystem_encoding, preferred_encoding
|
||||
from calibre import isbytestring
|
||||
|
||||
class Book(MetaInformation):
|
||||
|
||||
@ -105,7 +106,11 @@ class Book(MetaInformation):
|
||||
def to_json(self):
|
||||
json = {}
|
||||
for attr in self.JSON_ATTRS:
|
||||
json[attr] = getattr(self, attr)
|
||||
val = getattr(self, attr)
|
||||
if isbytestring(val):
|
||||
enc = filesystem_encoding if attr == 'lpath' else preferred_encoding
|
||||
val = val.decode(enc, 'replace')
|
||||
json[attr] = val
|
||||
return json
|
||||
|
||||
class BookList(_BookList):
|
||||
|
Loading…
x
Reference in New Issue
Block a user