diff --git a/src/tribler/core/components/libtorrent/download_manager/download_manager.py b/src/tribler/core/components/libtorrent/download_manager/download_manager.py index 2bdbc0046c4..c0ea5340d40 100644 --- a/src/tribler/core/components/libtorrent/download_manager/download_manager.py +++ b/src/tribler/core/components/libtorrent/download_manager/download_manager.py @@ -591,7 +591,8 @@ async def start_download_from_uri(self, uri, config=None): tdef = TorrentDef.load_from_dict(self.metainfo_cache[infohash]['meta_info']) else: self._logger.info('Metainfo not found in cache') - tdef = TorrentDefNoMetainfo(infohash, b"Unknown name" if not name else name, url=uri) + name_encoded = name.encode('utf8') if name else b"Unknown name" + tdef = TorrentDefNoMetainfo(infohash, name_encoded, url=uri) return await self.start_download(tdef=tdef, config=config) if scheme == FILE_SCHEME: self._logger.info('File scheme detected') diff --git a/src/tribler/core/components/libtorrent/tests/test_download_manager.py b/src/tribler/core/components/libtorrent/tests/test_download_manager.py index 1f4bb60492e..ed5ebfc5d45 100644 --- a/src/tribler/core/components/libtorrent/tests/test_download_manager.py +++ b/src/tribler/core/components/libtorrent/tests/test_download_manager.py @@ -511,6 +511,13 @@ async def test_start_download_from_magnet_no_name(fake_dlmgr: DownloadManager): assert download.tdef.get_name() == b'Unknown name' +async def test_start_download_from_magnet_with_name(fake_dlmgr: DownloadManager): + # Test whether a download is started with `Unknown name` name when the magnet has no name + magnet = f'magnet:?xt=urn:btih:{"A" * 40}&dn=AwesomeTorrent' + download = await fake_dlmgr.start_download_from_uri(magnet) + assert download.tdef.get_name() == b'AwesomeTorrent' + + def test_update_trackers(fake_dlmgr) -> None: fake_download, _ = create_fake_download_and_state() fake_dlmgr.downloads[fake_download.infohash] = fake_download