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 1a0003d852
4 changed files with 24 additions and 44 deletions

View File

@@ -20,7 +20,7 @@ from testify import teardown
import autojump_utils
from autojump_utils import create_dir
from autojump_utils import decode
from autojump_utils import encode
from autojump_utils import first
from autojump_utils import get_pwd
from autojump_utils import get_tab_entry_info
@@ -35,9 +35,10 @@ from autojump_utils import take
class StringUnitTests(TestCase):
def test_decode(self):
assert_equal(decode(r'blah'), u'blah')
assert_equal(decode(r'日本語'), u'日本語')
def test_encode(self):
assert_equal(encode(b'blah'), u'blah')
assert_equal(encode(b'日本語'), u'日本語')
assert_equal(encode(u'でもおれは中国人だ。'), u'でもおれは中国人だ。')
def test_has_uppercase(self):
assert_true(has_uppercase('Foo'))