mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
When using jsonify in modules, try several unicode encoding for dumps()
Fixes #4821
This commit is contained in:
@@ -840,7 +840,12 @@ class AnsibleModule(object):
|
|||||||
self.fail_json(msg='Boolean %s not in either boolean list' % arg)
|
self.fail_json(msg='Boolean %s not in either boolean list' % arg)
|
||||||
|
|
||||||
def jsonify(self, data):
|
def jsonify(self, data):
|
||||||
return json.dumps(data)
|
for encoding in ("utf-8", "latin-1", "unicode_escape"):
|
||||||
|
try:
|
||||||
|
return json.dumps(data, encoding=encoding)
|
||||||
|
except UnicodeDecodeError, e:
|
||||||
|
continue
|
||||||
|
self.fail_json(msg='Invalid unicode encoding encountered')
|
||||||
|
|
||||||
def from_json(self, data):
|
def from_json(self, data):
|
||||||
return json.loads(data)
|
return json.loads(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user