Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[W.I.P.] Use yaml.safe_load rather than yaml.load #6744

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/migration/migrate-compose-file-v1-to-v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def migrate(content):
data = ruamel.yaml.load(content, ruamel.yaml.RoundTripLoader)
data = ruamel.yaml.safe_load(content, ruamel.yaml.RoundTripLoader)

service_names = data.keys()

Expand Down
28 changes: 14 additions & 14 deletions tests/acceptance/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def test_config_default(self):
# assert there are no python objects encoded in the output
assert '!!' not in result.stdout

output = yaml.load(result.stdout)
output = yaml.safe_load(result.stdout)
expected = {
'version': '2.0',
'volumes': {'data': {'driver': 'local'}},
Expand All @@ -277,7 +277,7 @@ def test_config_default(self):
def test_config_restart(self):
self.base_dir = 'tests/fixtures/restart'
result = self.dispatch(['config'])
assert yaml.load(result.stdout) == {
assert yaml.safe_load(result.stdout) == {
'version': '2.0',
'services': {
'never': {
Expand Down Expand Up @@ -306,7 +306,7 @@ def test_config_restart(self):
def test_config_external_network(self):
self.base_dir = 'tests/fixtures/networks'
result = self.dispatch(['-f', 'external-networks.yml', 'config'])
json_result = yaml.load(result.stdout)
json_result = yaml.safe_load(result.stdout)
assert 'networks' in json_result
assert json_result['networks'] == {
'networks_foo': {
Expand All @@ -320,7 +320,7 @@ def test_config_external_network(self):
def test_config_with_dot_env(self):
self.base_dir = 'tests/fixtures/default-env-file'
result = self.dispatch(['config'])
json_result = yaml.load(result.stdout)
json_result = yaml.safe_load(result.stdout)
assert json_result == {
'services': {
'web': {
Expand All @@ -335,7 +335,7 @@ def test_config_with_dot_env(self):
def test_config_with_env_file(self):
self.base_dir = 'tests/fixtures/default-env-file'
result = self.dispatch(['--env-file', '.env2', 'config'])
json_result = yaml.load(result.stdout)
json_result = yaml.safe_load(result.stdout)
assert json_result == {
'services': {
'web': {
Expand All @@ -350,7 +350,7 @@ def test_config_with_env_file(self):
def test_config_with_dot_env_and_override_dir(self):
self.base_dir = 'tests/fixtures/default-env-file'
result = self.dispatch(['--project-directory', 'alt/', 'config'])
json_result = yaml.load(result.stdout)
json_result = yaml.safe_load(result.stdout)
assert json_result == {
'services': {
'web': {
Expand All @@ -365,7 +365,7 @@ def test_config_with_dot_env_and_override_dir(self):
def test_config_external_volume_v2(self):
self.base_dir = 'tests/fixtures/volumes'
result = self.dispatch(['-f', 'external-volumes-v2.yml', 'config'])
json_result = yaml.load(result.stdout)
json_result = yaml.safe_load(result.stdout)
assert 'volumes' in json_result
assert json_result['volumes'] == {
'foo': {
Expand All @@ -381,7 +381,7 @@ def test_config_external_volume_v2(self):
def test_config_external_volume_v2_x(self):
self.base_dir = 'tests/fixtures/volumes'
result = self.dispatch(['-f', 'external-volumes-v2-x.yml', 'config'])
json_result = yaml.load(result.stdout)
json_result = yaml.safe_load(result.stdout)
assert 'volumes' in json_result
assert json_result['volumes'] == {
'foo': {
Expand All @@ -397,7 +397,7 @@ def test_config_external_volume_v2_x(self):
def test_config_external_volume_v3_x(self):
self.base_dir = 'tests/fixtures/volumes'
result = self.dispatch(['-f', 'external-volumes-v3-x.yml', 'config'])
json_result = yaml.load(result.stdout)
json_result = yaml.safe_load(result.stdout)
assert 'volumes' in json_result
assert json_result['volumes'] == {
'foo': {
Expand All @@ -413,7 +413,7 @@ def test_config_external_volume_v3_x(self):
def test_config_external_volume_v3_4(self):
self.base_dir = 'tests/fixtures/volumes'
result = self.dispatch(['-f', 'external-volumes-v3-4.yml', 'config'])
json_result = yaml.load(result.stdout)
json_result = yaml.safe_load(result.stdout)
assert 'volumes' in json_result
assert json_result['volumes'] == {
'foo': {
Expand All @@ -429,7 +429,7 @@ def test_config_external_volume_v3_4(self):
def test_config_external_network_v3_5(self):
self.base_dir = 'tests/fixtures/networks'
result = self.dispatch(['-f', 'external-networks-v3-5.yml', 'config'])
json_result = yaml.load(result.stdout)
json_result = yaml.safe_load(result.stdout)
assert 'networks' in json_result
assert json_result['networks'] == {
'foo': {
Expand All @@ -445,7 +445,7 @@ def test_config_external_network_v3_5(self):
def test_config_v1(self):
self.base_dir = 'tests/fixtures/v1-config'
result = self.dispatch(['config'])
assert yaml.load(result.stdout) == {
assert yaml.safe_load(result.stdout) == {
'version': '2.1',
'services': {
'net': {
Expand All @@ -470,7 +470,7 @@ def test_config_v3(self):
self.base_dir = 'tests/fixtures/v3-full'
result = self.dispatch(['config'])

assert yaml.load(result.stdout) == {
assert yaml.safe_load(result.stdout) == {
'version': '3.5',
'volumes': {
'foobar': {
Expand Down Expand Up @@ -547,7 +547,7 @@ def test_config_compatibility_mode(self):
self.base_dir = 'tests/fixtures/compatibility-mode'
result = self.dispatch(['--compatibility', 'config'])

assert yaml.load(result.stdout) == {
assert yaml.safe_load(result.stdout) == {
'version': '2.3',
'volumes': {'foo': {'driver': 'default'}},
'networks': {'bar': {}},
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/config/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5030,7 +5030,7 @@ def test_healthcheck(self):
})
)

serialized_config = yaml.load(serialize_config(config_dict))
serialized_config = yaml.safe_load(serialize_config(config_dict))
serialized_service = serialized_config['services']['test']

assert serialized_service['healthcheck'] == {
Expand All @@ -5057,7 +5057,7 @@ def test_disable(self):
})
)

serialized_config = yaml.load(serialize_config(config_dict))
serialized_config = yaml.safe_load(serialize_config(config_dict))
serialized_service = serialized_config['services']['test']

assert serialized_service['healthcheck'] == {
Expand Down Expand Up @@ -5264,7 +5264,7 @@ def test_serialize_secrets(self):
'secrets': secrets_dict
}))

serialized_config = yaml.load(serialize_config(config_dict))
serialized_config = yaml.safe_load(serialize_config(config_dict))
serialized_service = serialized_config['services']['web']
assert secret_sort(serialized_service['secrets']) == secret_sort(service_dict['secrets'])
assert 'secrets' in serialized_config
Expand All @@ -5279,7 +5279,7 @@ def test_serialize_ports(self):
}
], volumes={}, networks={}, secrets={}, configs={})

serialized_config = yaml.load(serialize_config(config_dict))
serialized_config = yaml.safe_load(serialize_config(config_dict))
assert '8080:80/tcp' in serialized_config['services']['web']['ports']

def test_serialize_ports_with_ext_ip(self):
Expand All @@ -5291,7 +5291,7 @@ def test_serialize_ports_with_ext_ip(self):
}
], volumes={}, networks={}, secrets={}, configs={})

serialized_config = yaml.load(serialize_config(config_dict))
serialized_config = yaml.safe_load(serialize_config(config_dict))
assert '127.0.0.1:8080:80/tcp' in serialized_config['services']['web']['ports']

def test_serialize_configs(self):
Expand Down Expand Up @@ -5319,7 +5319,7 @@ def test_serialize_configs(self):
'configs': configs_dict
}))

serialized_config = yaml.load(serialize_config(config_dict))
serialized_config = yaml.safe_load(serialize_config(config_dict))
serialized_service = serialized_config['services']['web']
assert secret_sort(serialized_service['configs']) == secret_sort(service_dict['configs'])
assert 'configs' in serialized_config
Expand Down Expand Up @@ -5359,7 +5359,7 @@ def test_serialize_escape_dollar_sign(self):
}
config_dict = config.load(build_config_details(cfg))

serialized_config = yaml.load(serialize_config(config_dict))
serialized_config = yaml.safe_load(serialize_config(config_dict))
serialized_service = serialized_config['services']['web']
assert serialized_service['environment']['CURRENCY'] == '$$'
assert serialized_service['command'] == 'echo $$FOO'
Expand All @@ -5381,7 +5381,7 @@ def test_serialize_escape_dont_interpolate(self):
}
config_dict = config.load(build_config_details(cfg), interpolate=False)

serialized_config = yaml.load(serialize_config(config_dict, escape_dollar=False))
serialized_config = yaml.safe_load(serialize_config(config_dict, escape_dollar=False))
serialized_service = serialized_config['services']['web']
assert serialized_service['environment']['CURRENCY'] == '$'
assert serialized_service['command'] == 'echo $FOO'
Expand All @@ -5400,7 +5400,7 @@ def test_serialize_unicode_values(self):

config_dict = config.load(build_config_details(cfg))

serialized_config = yaml.load(serialize_config(config_dict))
serialized_config = yaml.safe_load(serialize_config(config_dict))
serialized_service = serialized_config['services']['web']
assert serialized_service['command'] == 'echo 十六夜 咲夜'

Expand All @@ -5416,6 +5416,6 @@ def test_serialize_external_false(self):
}

config_dict = config.load(build_config_details(cfg))
serialized_config = yaml.load(serialize_config(config_dict))
serialized_config = yaml.safe_load(serialize_config(config_dict))
serialized_volume = serialized_config['volumes']['test']
assert serialized_volume['external'] is False