Fixup unicode varReplace templating.
The original patches should have conflicted?53bde0bf51
vsefde61e537
This commit is contained in:
parent
262b35e7d3
commit
74e21e6154
2 changed files with 23 additions and 1 deletions
|
@ -235,7 +235,7 @@ def varReplace(raw, vars):
|
||||||
# original)
|
# original)
|
||||||
varname = m.group(2).lower()
|
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()
|
start, end = m.span()
|
||||||
done.append(raw[:start]) # Keep stuff leading up to token
|
done.append(raw[:start]) # Keep stuff leading up to token
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
@ -131,6 +133,16 @@ class TestUtils(unittest.TestCase):
|
||||||
|
|
||||||
assert res == 'hello 2'
|
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
|
### Template function tests
|
||||||
|
|
||||||
|
@ -153,3 +165,13 @@ class TestUtils(unittest.TestCase):
|
||||||
res = ansible.utils.template(template, vars, {}, no_engine=False)
|
res = ansible.utils.template(template, vars, {}, no_engine=False)
|
||||||
|
|
||||||
assert res == 'hello world\n'
|
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'
|
||||||
|
|
Loading…
Reference in a new issue