Skip to content

Commit

Permalink
Fixes Tribler#6633 UnicodeEncodeError "ascii codec can't encode chara…
Browse files Browse the repository at this point in the history
…cters in position" when saving TriblerConfig with non-ascii symbols
  • Loading branch information
kozlovsky committed Dec 20, 2021
1 parent 6bca340 commit c183dd7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/tribler-core/tribler_core/config/tests/test_tribler_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
CONFIG_PATH = TESTS_DATA_DIR / "config_files"


# fmt: off


@pytest.mark.asyncio
async def test_create(tmpdir):
config = TriblerConfig(state_dir=tmpdir)
Expand Down Expand Up @@ -52,6 +49,23 @@ async def test_load_write(tmpdir):
assert config.file == tmpdir / filename


@pytest.mark.asyncio
async def test_load_write_nonascii(tmpdir):
config = TriblerConfig(state_dir=tmpdir)
filename = 'test_read_write.ini'

config.download_defaults.saveas = 'ыюя'

assert not config.file
config.write(tmpdir / filename)
assert config.file == tmpdir / filename

config = TriblerConfig.load(file=tmpdir / filename, state_dir=tmpdir)

assert config.download_defaults.saveas == 'ыюя'
assert config.file == tmpdir / filename


@pytest.mark.asyncio
async def test_copy(tmpdir):
config = TriblerConfig(state_dir=tmpdir, file=tmpdir / '1.txt')
Expand Down
2 changes: 1 addition & 1 deletion src/tribler-core/tribler_core/config/tribler_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def write(self, file: Path = None):
'anon_proxy_auth': ...,
'anon_listen_port': ...,
'anon_proxy_server_ip': ...}})
conf = configobj.ConfigObj(dictionary)
conf = configobj.ConfigObj(dictionary, encoding='utf-8')
conf.filename = str(file)
conf.write()

Expand Down

0 comments on commit c183dd7

Please sign in to comment.