diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 4d2968ad..39d0eba9 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -674,7 +674,7 @@ def parse_env_file(env_file): def split_command(command): - if six.PY2: + if six.PY2 and not isinstance(command, six.binary_type): command = command.encode('utf-8') return shlex.split(command) diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index c20fa5f6..93f95a1e 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -392,14 +392,18 @@ class UtilsTest(base.BaseTestCase): class SplitCommandTest(base.BaseTestCase): - @pytest.mark.skipif(six.PY2, reason="shlex doesn't support unicode in py2") def test_split_command_with_unicode(self): - self.assertEqual(split_command('echo μ'), ['echo', 'μ']) + if six.PY2: + self.assertEqual( + split_command(unicode('echo μμ', 'utf-8')), + ['echo', 'μμ'] + ) + else: + self.assertEqual(split_command('echo μμ'), ['echo', 'μμ']) - @pytest.mark.skipif(six.PY3, reason="shlex doesn't support unicode in py2") + @pytest.mark.skipif(six.PY3, reason="shlex doesn't support bytes in py3") def test_split_command_with_bytes(self): - expected = ['echo', u'μ'.encode('utf-8')] - self.assertEqual(split_command(u'echo μ'), expected) + self.assertEqual(split_command('echo μμ'), ['echo', 'μμ']) class PortsTest(base.BaseTestCase):