[#2418] Fix WebUI error when adding non-ascii torrent

json.dumps attempts to decode (utf8) the 'path' entry which had a
alternative encoding. The solution is to ensure the 'path' entry is
utf8 encoded and remove the unneeded 'path.utf-8' entry.

As self.__m_metadata["info"]["files"] is updated the later code
checking and decoding the 'path' entry can be removed.
This commit is contained in:
Calum Lind 2014-07-08 14:56:31 +01:00
parent 7aa52e5f1b
commit 67873f39dc
1 changed files with 3 additions and 5 deletions

View File

@ -98,8 +98,10 @@ class TorrentInfo(object):
for index, f in enumerate(self.__m_metadata["info"]["files"]): for index, f in enumerate(self.__m_metadata["info"]["files"]):
if "path.utf-8" in f: if "path.utf-8" in f:
path = os.path.join(prefix, *f["path.utf-8"]) path = os.path.join(prefix, *f["path.utf-8"])
del f["path.utf-8"]
else: else:
path = utf8_encoded(os.path.join(prefix, utf8_encoded(os.path.join(*f["path"]), self.encoding)), self.encoding) path = utf8_encoded(os.path.join(prefix, utf8_encoded(os.path.join(*f["path"]), self.encoding)), self.encoding)
f["path"] = path
f["index"] = index f["index"] = index
if "sha1" in f and len(f["sha1"]) == 20: if "sha1" in f and len(f["sha1"]) == 20:
f["sha1"] = f["sha1"].encode('hex') f["sha1"] = f["sha1"].encode('hex')
@ -155,12 +157,8 @@ class TorrentInfo(object):
prefix = self.__m_name prefix = self.__m_name
for f in self.__m_metadata["info"]["files"]: for f in self.__m_metadata["info"]["files"]:
if "path.utf-8" in f:
path = os.path.join(prefix, *f["path.utf-8"])
else:
path = utf8_encoded(os.path.join(prefix, utf8_encoded(os.path.join(*f["path"]), self.encoding)), self.encoding)
self.__m_files.append({ self.__m_files.append({
'path': path, 'path': f["path"],
'size': f["length"], 'size': f["length"],
'download': True 'download': True
}) })