From f8451aab381c67edb395d6df58a7fe0d42be0aa3 Mon Sep 17 00:00:00 2001 From: pkoprda <47797196+pkoprda@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:22:08 +0100 Subject: [PATCH] fix(client): Serialize properly escape characters (#4335) * Card ID: CCT-1065 Backslashes in regex patterns were not properly escaped, causing inconsistencies between Fedora 40 and CentOS Stream 9 environments. This commit ensures that all escape characters are properly serialized. Signed-off-by: pkoprda --- .../apps/ansible/playbook_verifier/serializer.py | 13 +++++++++++++ .../tests/client/apps/test_playbook_verifier.py | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) 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):