1
0
mirror of https://github.com/wting/autojump synced 2026-03-02 03:49:26 +00:00

Fix encoding issues.

The original implementation used str.encode() on input and str.decode() on
output. However this would cause UnicodeDecodeError since certain characters
can't be encoded / decoded in ASCII.

The new solution is to use unicode() on all input strings and output UTF-8
encoded strings. This makes the assumption that the shell can handle UTF-8
strings.
This commit is contained in:
William Ting
2014-01-07 11:44:44 -06:00
parent 3f460fb3e9
commit 35bc63c66e
5 changed files with 66 additions and 48 deletions

View File

@@ -17,6 +17,7 @@ else:
from itertools import imap
from autojump_utils import create_dir
from autojump_utils import unico
from autojump_utils import is_osx
from autojump_utils import is_python3
from autojump_utils import move_file
@@ -124,11 +125,7 @@ def save(config, data):
encoding='utf-8',
errors='replace') as f:
for path, weight in data.items():
if is_python3():
f.write(("%s\t%s\n" % (weight, path)))
else:
f.write(unicode(
"%s\t%s\n" % (weight, path)).encode('utf-8'))
f.write(unico("%s\t%s\n" % (weight, path)))
f.flush()
os.fsync(f)