mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
When using jsonify in modules, try several unicode encoding for dumps()
Fixes #4821
This commit is contained in:
parent
ce0b1a8a96
commit
a023cbce14
1 changed files with 6 additions and 1 deletions
|
@ -840,7 +840,12 @@ class AnsibleModule(object):
|
|||
self.fail_json(msg='Boolean %s not in either boolean list' % arg)
|
||||
|
||||
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):
|
||||
return json.loads(data)
|
||||
|
|
Loading…
Reference in a new issue