summaryrefslogtreecommitdiff
path: root/lib/ansible/module_utils/common/text/converters.py
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2023-04-18 12:01:47 -0500
committerGitHub <noreply@github.com>2023-04-18 12:01:47 -0500
commitf90c7f1a7d38f317b3d22977f06ef1b15311a4a7 (patch)
tree09f8954d189f770624298e35164ba9a8df41f2c4 /lib/ansible/module_utils/common/text/converters.py
parent12083db2c535f2de0c50c5fb14a47e43c289f703 (diff)
downloadansible-f90c7f1a7d38f317b3d22977f06ef1b15311a4a7.tar.gz
[stable-2.15] Implement checks, and backwards compat change, to move forward with UTF-8 only (#80370) (#80545)
(cherry picked from commit 0ee7cfb)
Diffstat (limited to 'lib/ansible/module_utils/common/text/converters.py')
-rw-r--r--lib/ansible/module_utils/common/text/converters.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/ansible/module_utils/common/text/converters.py b/lib/ansible/module_utils/common/text/converters.py
index dcfb89a8d7..f33e76cd68 100644
--- a/lib/ansible/module_utils/common/text/converters.py
+++ b/lib/ansible/module_utils/common/text/converters.py
@@ -268,18 +268,13 @@ def _json_encode_fallback(obj):
def jsonify(data, **kwargs):
+ # After 2.18, we should remove this loop, and hardcode to utf-8 in alignment with requiring utf-8 module responses
for encoding in ("utf-8", "latin-1"):
try:
- return json.dumps(data, encoding=encoding, default=_json_encode_fallback, **kwargs)
- # Old systems using old simplejson module does not support encoding keyword.
- except TypeError:
- try:
- new_data = container_to_text(data, encoding=encoding)
- except UnicodeDecodeError:
- continue
- return json.dumps(new_data, default=_json_encode_fallback, **kwargs)
+ new_data = container_to_text(data, encoding=encoding)
except UnicodeDecodeError:
continue
+ return json.dumps(new_data, default=_json_encode_fallback, **kwargs)
raise UnicodeError('Invalid unicode encoding encountered')