mirror of
https://github.com/docker/compose.git
synced 2025-07-25 22:54:54 +02:00
Merge pull request #3964 from shin-/3963-unicode-env
Don't break when interpolating environment with unicode characters
This commit is contained in:
commit
e4bb9bde30
@ -1111,6 +1111,8 @@ 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 '{key}={value}'.format(key=key, value=value)
|
return '{key}={value}'.format(key=key, value=value)
|
||||||
return [format_env(*item) for item in environment.items()]
|
return [format_env(*item) for item in environment.items()]
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ from collections import namedtuple
|
|||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
|
|
||||||
import py
|
import py
|
||||||
|
import six
|
||||||
import yaml
|
import yaml
|
||||||
from docker import errors
|
from docker import errors
|
||||||
|
|
||||||
@ -1286,6 +1288,23 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
'simplecomposefile_simple_run_1',
|
'simplecomposefile_simple_run_1',
|
||||||
'exited'))
|
'exited'))
|
||||||
|
|
||||||
|
@mock.patch.dict(os.environ)
|
||||||
|
def test_run_unicode_env_values_from_system(self):
|
||||||
|
value = 'ą, ć, ę, ł, ń, ó, ś, ź, ż'
|
||||||
|
if six.PY2: # os.environ doesn't support unicode values in Py2
|
||||||
|
os.environ['BAR'] = value.encode('utf-8')
|
||||||
|
else: # ... and doesn't support byte values in Py3
|
||||||
|
os.environ['BAR'] = value
|
||||||
|
self.base_dir = 'tests/fixtures/unicode-environment'
|
||||||
|
result = self.dispatch(['run', 'simple'])
|
||||||
|
|
||||||
|
if six.PY2: # Can't retrieve output on Py3. See issue #3670
|
||||||
|
assert value == result.stdout.strip()
|
||||||
|
|
||||||
|
container = self.project.containers(one_off=OneOffFilter.only, stopped=True)[0]
|
||||||
|
environment = container.get('Config.Env')
|
||||||
|
assert 'FOO={}'.format(value) in environment
|
||||||
|
|
||||||
@mock.patch.dict(os.environ)
|
@mock.patch.dict(os.environ)
|
||||||
def test_run_env_values_from_system(self):
|
def test_run_env_values_from_system(self):
|
||||||
os.environ['FOO'] = 'bar'
|
os.environ['FOO'] = 'bar'
|
||||||
|
7
tests/fixtures/unicode-environment/docker-compose.yml
vendored
Normal file
7
tests/fixtures/unicode-environment/docker-compose.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
version: '2'
|
||||||
|
services:
|
||||||
|
simple:
|
||||||
|
image: busybox:latest
|
||||||
|
command: sh -c 'echo $$FOO'
|
||||||
|
environment:
|
||||||
|
FOO: ${BAR}
|
Loading…
x
Reference in New Issue
Block a user