From 74e21e61548267ded43769c9471b57010af285ae Mon Sep 17 00:00:00 2001 From: Jeroen Hoekx Date: Thu, 10 May 2012 10:11:14 +0200 Subject: [PATCH] Fixup unicode varReplace templating. The original patches should have conflicted? 53bde0bf517d1302c80f80180f85995efa36a00e vs efde61e53729964f3e740dcbb9c52f889186719d --- lib/ansible/utils.py | 2 +- test/TestUtils.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index 55b7a55f31..9518b3ae80 100644 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -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 diff --git a/test/TestUtils.py b/test/TestUtils.py index 42953b854a..7f924da9b0 100644 --- a/test/TestUtils.py +++ b/test/TestUtils.py @@ -1,3 +1,5 @@ +# -*- 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'