mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -02:30
add more edge case handling for yaml unsafe marking
This commit is contained in:
@@ -20,6 +20,18 @@ def test_raw_string():
|
|||||||
assert safe_dump('foo') == "!unsafe 'foo'\n"
|
assert safe_dump('foo') == "!unsafe 'foo'\n"
|
||||||
|
|
||||||
|
|
||||||
|
def test_kv_null():
|
||||||
|
assert safe_dump({'a': None}) == "!unsafe 'a': null\n"
|
||||||
|
|
||||||
|
|
||||||
|
def test_kv_null_safe():
|
||||||
|
assert safe_dump({'a': None}, {'a': None}) == "a: null\n"
|
||||||
|
|
||||||
|
|
||||||
|
def test_kv_null_unsafe():
|
||||||
|
assert safe_dump({'a': ''}, {'a': None}) == "!unsafe 'a': !unsafe ''\n"
|
||||||
|
|
||||||
|
|
||||||
def test_kv_int():
|
def test_kv_int():
|
||||||
assert safe_dump({'a': 1}) == "!unsafe 'a': 1\n"
|
assert safe_dump({'a': 1}) == "!unsafe 'a': 1\n"
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ def safe_dump(x, safe_dict=None):
|
|||||||
# equality matches (and consider those branches safe)
|
# equality matches (and consider those branches safe)
|
||||||
for k, v in x.items():
|
for k, v in x.items():
|
||||||
dumper = yaml.SafeDumper
|
dumper = yaml.SafeDumper
|
||||||
if safe_dict.get(k) != v:
|
if k not in safe_dict or safe_dict.get(k) != v:
|
||||||
dumper = SafeStringDumper
|
dumper = SafeStringDumper
|
||||||
yamls.append(yaml.dump_all(
|
yamls.append(yaml.dump_all(
|
||||||
[{k: v}],
|
[{k: v}],
|
||||||
|
|||||||
Reference in New Issue
Block a user