mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-20 00:09:15 +00:00
[#3204|Core] Fix unicode get_name unicode error
The recent change to torrent.get_name does not handle non-ascii paths on Python 2. - Add a decode_bytes to resolve the issue. - Add tests. - Refactor to reduce nesting.
This commit is contained in:
parent
9ab2a50097
commit
b834e33568
@ -933,23 +933,18 @@ class Torrent(object):
|
||||
str: the name of the torrent.
|
||||
|
||||
"""
|
||||
if not self.options['name']:
|
||||
# Use the top-level folder as torrent name.
|
||||
if self.has_metadata:
|
||||
handle_name = (
|
||||
self.torrent_info.file_at(0)
|
||||
.path.replace('\\', '/', 1)
|
||||
.split('/', 1)[0]
|
||||
)
|
||||
else:
|
||||
handle_name = self.handle.name()
|
||||
if self.options['name']:
|
||||
return self.options['name']
|
||||
|
||||
if handle_name:
|
||||
name = decode_bytes(handle_name)
|
||||
else:
|
||||
name = self.torrent_id
|
||||
if self.has_metadata:
|
||||
# Use the top-level folder as torrent name.
|
||||
filename = decode_bytes(self.torrent_info.file_at(0).path)
|
||||
name = filename.replace('\\', '/', 1).split('/', 1)[0]
|
||||
else:
|
||||
name = self.options['name']
|
||||
name = decode_bytes(self.handle.name())
|
||||
|
||||
if not name:
|
||||
name = self.torrent_id
|
||||
|
||||
return name
|
||||
|
||||
|
1
deluge/tests/data/unicode_file.torrent
Normal file
1
deluge/tests/data/unicode_file.torrent
Normal file
@ -0,0 +1 @@
|
||||
d13:creation datei1540200743e8:encoding5:UTF-84:infod6:lengthi0e4:name35:সুকুমার রায়.mkv12:piece lengthi32768e6:pieces0:7:privatei0eee
|
@ -297,3 +297,10 @@ class TorrentTestCase(BaseTestCase):
|
||||
result = self.torrent.get_eta()
|
||||
self.assertEqual(result, 100)
|
||||
self.assertIsInstance(result, int)
|
||||
|
||||
def test_get_name_unicode(self):
|
||||
"""Test retrieving a unicode torrent name from libtorrent."""
|
||||
atp = self.get_torrent_atp('unicode_file.torrent')
|
||||
handle = self.session.add_torrent(atp)
|
||||
self.torrent = Torrent(handle, {})
|
||||
self.assertEqual(self.torrent.get_name(), 'সুকুমার রায়.mkv')
|
||||
|
Loading…
x
Reference in New Issue
Block a user