Kaydet (Commit) 14634fb5 authored tarafından Joffrey F's avatar Joffrey F Kaydeden (comit) GitHub

Merge pull request #1256 from docker/format_env_unicode_bug

Do not break when calling format_environment with unicode values
...@@ -1001,6 +1001,9 @@ def format_environment(environment): ...@@ -1001,6 +1001,9 @@ def format_environment(environment):
def format_env(key, value): def format_env(key, value):
if value is None: if value is None:
return key return key
if isinstance(value, six.binary_type):
value = value.decode('utf-8')
return u'{key}={value}'.format(key=key, value=value) return u'{key}={value}'.format(key=key, value=value)
return [format_env(*var) for var in six.iteritems(environment)] return [format_env(*var) for var in six.iteritems(environment)]
......
...@@ -20,11 +20,11 @@ from docker.utils import ( ...@@ -20,11 +20,11 @@ from docker.utils import (
create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file, create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file,
exclude_paths, convert_volume_binds, decode_json_header, tar, exclude_paths, convert_volume_binds, decode_json_header, tar,
split_command, create_ipam_config, create_ipam_pool, parse_devices, split_command, create_ipam_config, create_ipam_pool, parse_devices,
update_headers, update_headers
) )
from docker.utils.ports import build_port_bindings, split_port from docker.utils.ports import build_port_bindings, split_port
from docker.utils.utils import create_endpoint_config from docker.utils.utils import create_endpoint_config, format_environment
from .. import base from .. import base
from ..helpers import make_tree from ..helpers import make_tree
...@@ -1047,3 +1047,18 @@ class TarTest(base.Cleanup, base.BaseTestCase): ...@@ -1047,3 +1047,18 @@ class TarTest(base.Cleanup, base.BaseTestCase):
self.assertEqual( self.assertEqual(
sorted(tar_data.getnames()), ['bar', 'bar/foo', 'foo'] sorted(tar_data.getnames()), ['bar', 'bar/foo', 'foo']
) )
class FormatEnvironmentTest(base.BaseTestCase):
def test_format_env_binary_unicode_value(self):
env_dict = {
'ARTIST_NAME': b'\xec\x86\xa1\xec\xa7\x80\xec\x9d\x80'
}
assert format_environment(env_dict) == [u'ARTIST_NAME=송지은']
def test_format_env_no_value(self):
env_dict = {
'FOO': None,
'BAR': '',
}
assert sorted(format_environment(env_dict)) == ['BAR=', 'FOO']
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment