Skip to content

Commit

Permalink
fix(client): Support playbooks with unicode for Python 3.12+
Browse files Browse the repository at this point in the history
* Card ID: CCT-644

Some Unicode characters, like the zero-width joiner in emojis, were not
processed correctly. This update improves Unicode support, mainly aimed
for Python 3.12+.

Signed-off-by: pkoprda <[email protected]>
  • Loading branch information
pkoprda committed Jan 20, 2025
1 parent 2afde47 commit f4c9980
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def _str(cls, value):
"\\": "\\\\",
"\n": "\\n",
"\t": "\\t",
"\u200d": "\\u200d", # Zero-width joiner
}
escaped_string = ""
for char in value:
Expand Down
11 changes: 9 additions & 2 deletions insights/tests/client/apps/test_playbook_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ def test_strings(self, source, expected):
result = playbook_verifier.PlaybookSerializer.serialize(source)
assert result == expected

def test_strings_emoji_zwj(self):
if sys.version_info < (3, 0):
raise pytest.skip("Unicode characters are not supported on Python 2 systems")

source = "👨🏼‍🚀"
result = playbook_verifier.PlaybookSerializer.serialize(source)
expected = "'👨🏼\\u200d🚀'"
assert result == expected


class TestSerializePlaybookSnippet:
def test_serialize_dictionary(self):
Expand Down Expand Up @@ -429,8 +438,6 @@ def test_small(self):
def test_real(self, filename):
if filename == "unicode" and sys.version_info < (3, 0):
raise pytest.skip("Playbooks containing unicode are not supported in Python 2 systems")
if filename == "unicode" and sys.version_info >= (3, 12):
raise pytest.xfail("Known RFE in Unicode serialization.")

parent = os.path.dirname(__file__) # type: str
with open("{parent}/playbooks/{filename}.yml".format(parent=parent, filename=filename), "r") as f:
Expand Down

0 comments on commit f4c9980

Please sign in to comment.