diff --git a/insights/client/apps/ansible/playbook_verifier/serializer.py b/insights/client/apps/ansible/playbook_verifier/serializer.py index 10d328c019..759cba031b 100644 --- a/insights/client/apps/ansible/playbook_verifier/serializer.py +++ b/insights/client/apps/ansible/playbook_verifier/serializer.py @@ -49,7 +49,20 @@ def _str(cls, value): # single'quote "single'quote" # double"quote 'double"quote' # both"'quotes 'both"\'quotes' + # \backslash '\\backslash' + # new\nline 'new\\nline' + # tab\tchar 'tab\\tchar' + special_chars = { + "\\": "\\\\", + "\n": "\\n", + "\t": "\\t", + } + escaped_string = "" + for char in value: + escaped_string += special_chars.get(char, char) + + value = escaped_string quote = "'" if "'" in value: if '"' not in value: diff --git a/insights/tests/client/apps/test_playbook_verifier.py b/insights/tests/client/apps/test_playbook_verifier.py index bd56240c2a..570b76afff 100644 --- a/insights/tests/client/apps/test_playbook_verifier.py +++ b/insights/tests/client/apps/test_playbook_verifier.py @@ -366,7 +366,10 @@ def test_numbers(self, source, expected): ("no quote", "'no quote'"), ("single'quote", '''"single'quote"'''), ("double\"quote", """'double"quote'"""), - ("both\"'quotes", r"""'both"\'quotes'""") + ("both\"'quotes", r"""'both"\'quotes'"""), + ("\\backslash", "'\\\\backslash'"), + ("new\nline", "'new\\nline'"), + ("tab\tchar", "'tab\\tchar'"), ] ) def test_strings(self, source, expected):