mirror of
https://github.com/valitydev/salt.git
synced 2024-11-09 01:36:48 +00:00
Ensure that we don't feed jinja2.Markup() a str type
If the dumped contents contain non-ascii unicode, this will cause a UnicodeDecodeError.
This commit is contained in:
parent
b412bff534
commit
f5f16cf483
@ -817,14 +817,21 @@ class SerializerExtension(Extension, object):
|
||||
return explore(data)
|
||||
|
||||
def format_json(self, value, sort_keys=True, indent=None):
|
||||
return Markup(salt.utils.json.dumps(value, sort_keys=sort_keys, indent=indent).strip())
|
||||
json_txt = salt.utils.json.dumps(value, sort_keys=sort_keys, indent=indent).strip()
|
||||
try:
|
||||
return Markup(json_txt)
|
||||
except UnicodeDecodeError:
|
||||
return Markup(salt.utils.stringutils.to_unicode(json_txt))
|
||||
|
||||
def format_yaml(self, value, flow_style=True):
|
||||
yaml_txt = salt.utils.yaml.safe_dump(
|
||||
value, default_flow_style=flow_style).strip()
|
||||
if yaml_txt.endswith('\n...'):
|
||||
if yaml_txt.endswith(str('\n...')): # future lint: disable=blacklisted-function
|
||||
yaml_txt = yaml_txt[:len(yaml_txt)-4]
|
||||
return Markup(yaml_txt)
|
||||
try:
|
||||
return Markup(yaml_txt)
|
||||
except UnicodeDecodeError:
|
||||
return Markup(salt.utils.stringutils.to_unicode(yaml_txt))
|
||||
|
||||
def format_xml(self, value):
|
||||
"""Render a formatted multi-line XML string from a complex Python
|
||||
|
Loading…
Reference in New Issue
Block a user