Skip to content

Commit

Permalink
fix(client): Serialize properly escape characters (#4335)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
pkoprda authored Jan 15, 2025
1 parent c530404 commit f8451aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions insights/client/apps/ansible/playbook_verifier/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion insights/tests/client/apps/test_playbook_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f8451aa

Please sign in to comment.