mirror of
https://github.com/docker/compose.git
synced 2025-04-08 17:05:13 +02:00
Escape dollar sign in serialized config output
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
9502408ff0
commit
7abae9f536
@ -21,8 +21,11 @@ def serialize_dict_type(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
|
||||
|
||||
data = data.replace('$', '$$')
|
||||
|
||||
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
|
||||
# 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 'FOO: "Y"\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