mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
Do not escape backslashes when processing a template file.
Fixes #12198 Fixes #12241
This commit is contained in:
parent
21ee4b02da
commit
e218bf8da9
4 changed files with 32 additions and 15 deletions
|
@ -33,12 +33,6 @@ from units.mock.loader import DictDataLoader
|
|||
class TestTemplar(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_templar_simple(self):
|
||||
fake_loader = DictDataLoader({
|
||||
"/path/to/my_file.txt": "foo\n",
|
||||
})
|
||||
|
@ -54,8 +48,14 @@ class TestTemplar(unittest.TestCase):
|
|||
var_list=[1],
|
||||
recursive="{{recursive}}",
|
||||
)
|
||||
templar = Templar(loader=fake_loader, variables=variables)
|
||||
self.templar = Templar(loader=fake_loader, variables=variables)
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_templar_simple(self):
|
||||
|
||||
templar = self.templar
|
||||
# test some basic templating
|
||||
self.assertEqual(templar.template("{{foo}}"), "bar")
|
||||
self.assertEqual(templar.template("{{foo}}\n"), "bar\n")
|
||||
|
@ -89,6 +89,20 @@ class TestTemplar(unittest.TestCase):
|
|||
# variables must be a dict() for set_available_variables()
|
||||
self.assertRaises(AssertionError, templar.set_available_variables, "foo=bam")
|
||||
|
||||
def test_templar_escape_backslashes(self):
|
||||
# Rule of thumb: If escape backslashes is True you should end up with
|
||||
# the same number of backslashes as when you started.
|
||||
self.assertEqual(self.templar.template("\t{{foo}}", escape_backslashes=True), "\tbar")
|
||||
self.assertEqual(self.templar.template("\t{{foo}}", escape_backslashes=False), "\tbar")
|
||||
self.assertEqual(self.templar.template("\\{{foo}}", escape_backslashes=True), "\\bar")
|
||||
self.assertEqual(self.templar.template("\\{{foo}}", escape_backslashes=False), "\\bar")
|
||||
self.assertEqual(self.templar.template("\\{{foo + '\t' }}", escape_backslashes=True), "\\bar\t")
|
||||
self.assertEqual(self.templar.template("\\{{foo + '\t' }}", escape_backslashes=False), "\\bar\t")
|
||||
self.assertEqual(self.templar.template("\\{{foo + '\\t' }}", escape_backslashes=True), "\\bar\\t")
|
||||
self.assertEqual(self.templar.template("\\{{foo + '\\t' }}", escape_backslashes=False), "\\bar\t")
|
||||
self.assertEqual(self.templar.template("\\{{foo + '\\\\t' }}", escape_backslashes=True), "\\bar\\\\t")
|
||||
self.assertEqual(self.templar.template("\\{{foo + '\\\\t' }}", escape_backslashes=False), "\\bar\\t")
|
||||
|
||||
def test_template_jinja2_extensions(self):
|
||||
fake_loader = DictDataLoader({})
|
||||
templar = Templar(loader=fake_loader)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue