Skip to content

Commit 4028e29

Browse files
committed
Do not break when calling format_environment with unicode values
Signed-off-by: Joffrey F <[email protected]>
1 parent c983950 commit 4028e29

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docker/utils/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,9 @@ def format_environment(environment):
986986
def format_env(key, value):
987987
if value is None:
988988
return key
989+
if isinstance(value, six.binary_type):
990+
value = value.decode('utf-8')
991+
989992
return u'{key}={value}'.format(key=key, value=value)
990993
return [format_env(*var) for var in six.iteritems(environment)]
991994

tests/unit/utils_test.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file,
2121
exclude_paths, convert_volume_binds, decode_json_header, tar,
2222
split_command, create_ipam_config, create_ipam_pool, parse_devices,
23-
update_headers,
23+
update_headers
2424
)
2525

2626
from docker.utils.ports import build_port_bindings, split_port
27-
from docker.utils.utils import create_endpoint_config
27+
from docker.utils.utils import create_endpoint_config, format_environment
2828

2929
from .. import base
3030
from ..helpers import make_tree
@@ -1047,3 +1047,18 @@ def test_tar_with_directory_symlinks(self):
10471047
self.assertEqual(
10481048
sorted(tar_data.getnames()), ['bar', 'bar/foo', 'foo']
10491049
)
1050+
1051+
1052+
class FormatEnvironmentTest(base.BaseTestCase):
1053+
def test_format_env_binary_unicode_value(self):
1054+
env_dict = {
1055+
'ARTIST_NAME': b'\xec\x86\xa1\xec\xa7\x80\xec\x9d\x80'
1056+
}
1057+
assert format_environment(env_dict) == [u'ARTIST_NAME=송지은']
1058+
1059+
def test_format_env_no_value(self):
1060+
env_dict = {
1061+
'FOO': None,
1062+
'BAR': '',
1063+
}
1064+
assert sorted(format_environment(env_dict)) == ['BAR=', 'FOO']

0 commit comments

Comments
 (0)