mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #36611 from multani/2015.8
jinja: fix YAML terminator removal in Jinja's "yaml" filter
This commit is contained in:
commit
5de036b56c
2 changed files with 8 additions and 2 deletions
|
@ -384,8 +384,8 @@ class SerializerExtension(Extension, object):
|
|||
def format_yaml(self, value, flow_style=True):
|
||||
yaml_txt = yaml.dump(value, default_flow_style=flow_style,
|
||||
Dumper=OrderedDictDumper).strip()
|
||||
if yaml_txt.endswith('\n...\n'):
|
||||
yaml_txt = yaml_txt[:len(yaml_txt-5)]
|
||||
if yaml_txt.endswith('\n...'):
|
||||
yaml_txt = yaml_txt[:len(yaml_txt)-4]
|
||||
return Markup(yaml_txt)
|
||||
|
||||
def format_python(self, value):
|
||||
|
|
|
@ -477,6 +477,12 @@ class TestCustomExtensions(TestCase):
|
|||
rendered = env.from_string('{{ dataset|yaml }}').render(dataset=dataset)
|
||||
self.assertEqual(dataset, yaml.load(rendered))
|
||||
|
||||
def test_serialize_yaml_str(self):
|
||||
dataset = "str value"
|
||||
env = Environment(extensions=[SerializerExtension])
|
||||
rendered = env.from_string('{{ dataset|yaml }}').render(dataset=dataset)
|
||||
self.assertEqual(dataset, rendered)
|
||||
|
||||
def test_serialize_python(self):
|
||||
dataset = {
|
||||
"foo": True,
|
||||
|
|
Loading…
Add table
Reference in a new issue