Commit b90c2356 by Michael DeHaan

Merge pull request #349 from jhoekx/template-unicode-fixes

Fixup unicode varReplace templating.
parents 461ba572 c362a2e5
......@@ -235,7 +235,7 @@ def varReplace(raw, vars):
# original)
varname = m.group(2).lower()
replacement = str(varLookup(varname, vars) or m.group())
replacement = unicode(varLookup(varname, vars) or m.group())
start, end = m.span()
done.append(raw[:start]) # Keep stuff leading up to token
......
# -*- coding: utf-8 -*-
import os
import unittest
......@@ -131,6 +133,16 @@ class TestUtils(unittest.TestCase):
assert res == 'hello 2'
def test_varReplace_unicode(self):
template = 'hello $who'
vars = {
'who': u'wórld',
}
res = ansible.utils.varReplace(template, vars)
assert res == u'hello wórld'
#####################################
### Template function tests
......@@ -153,3 +165,13 @@ class TestUtils(unittest.TestCase):
res = ansible.utils.template(template, vars, {}, no_engine=False)
assert res == 'hello world\n'
def test_template_unicode(self):
template = 'hello {{ who }}'
vars = {
'who': u'wórld',
}
res = ansible.utils.template(template, vars, {}, no_engine=False)
assert res == u'hello wórld'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment