mirror of
https://github.com/docker/compose.git
synced 2025-07-24 06:04:57 +02:00
Escape dollar sign in serialized config output
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
73fd0abd5b
commit
770d94376a
@ -21,8 +21,11 @@ def serialize_dict_type(dumper, data):
|
|||||||
|
|
||||||
|
|
||||||
def serialize_string(dumper, data):
|
def serialize_string(dumper, data):
|
||||||
""" Ensure boolean-like strings are quoted in the output """
|
""" Ensure boolean-like strings are quoted in the output and escape $ characters """
|
||||||
representer = dumper.represent_str if six.PY3 else dumper.represent_unicode
|
representer = dumper.represent_str if six.PY3 else dumper.represent_unicode
|
||||||
|
|
||||||
|
data = data.replace('$', '$$')
|
||||||
|
|
||||||
if data.lower() in ('y', 'n', 'yes', 'no', 'on', 'off', 'true', 'false'):
|
if data.lower() in ('y', 'n', 'yes', 'no', 'on', 'off', 'true', 'false'):
|
||||||
# Empirically only y/n appears to be an issue, but this might change
|
# Empirically only y/n appears to be an issue, but this might change
|
||||||
# depending on which PyYaml version is being used. Err on safe side.
|
# depending on which PyYaml version is being used. Err on safe side.
|
||||||
|
@ -4185,3 +4185,25 @@ class SerializeTest(unittest.TestCase):
|
|||||||
assert 'command: "true"\n' in serialized_config
|
assert 'command: "true"\n' in serialized_config
|
||||||
assert 'FOO: "Y"\n' in serialized_config
|
assert 'FOO: "Y"\n' in serialized_config
|
||||||
assert 'BAR: "on"\n' in serialized_config
|
assert 'BAR: "on"\n' in serialized_config
|
||||||
|
|
||||||
|
def test_serialize_escape_dollar_sign(self):
|
||||||
|
cfg = {
|
||||||
|
'version': '2.2',
|
||||||
|
'services': {
|
||||||
|
'web': {
|
||||||
|
'image': 'busybox',
|
||||||
|
'command': 'echo $$FOO',
|
||||||
|
'environment': {
|
||||||
|
'CURRENCY': '$$'
|
||||||
|
},
|
||||||
|
'entrypoint': ['$$SHELL', '-c'],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config_dict = config.load(build_config_details(cfg))
|
||||||
|
|
||||||
|
serialized_config = yaml.load(serialize_config(config_dict))
|
||||||
|
serialized_service = serialized_config['services']['web']
|
||||||
|
assert serialized_service['environment']['CURRENCY'] == '$$'
|
||||||
|
assert serialized_service['command'] == 'echo $$FOO'
|
||||||
|
assert serialized_service['entrypoint'][0] == '$$SHELL'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user