From 57f8eaa19b27513aa3f268775c84340187bc8ef9 Mon Sep 17 00:00:00 2001 From: Ethan Lynn Date: Mon, 16 Jun 2014 13:57:50 +0800 Subject: [PATCH] Fix String Parameter Receive a unicode Add unicode encode to parameter to make sure unicode will be accepted correctly. Change-Id: Idc9afad7971eaf0320d719946a3f09b8e15c1479 Closes-Bug: #1330370 (cherry picked from commit 7b8d32d58195a2b9098c837fe997d334e2529b8d) --- heat/engine/parameters.py | 4 +++- heat/tests/test_parameters.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/heat/engine/parameters.py b/heat/engine/parameters.py index c20d82444c..944a57c8dc 100644 --- a/heat/engine/parameters.py +++ b/heat/engine/parameters.py @@ -15,9 +15,11 @@ import collections import itertools import json +import six from heat.engine import constraints as constr from heat.common import exception +from heat.openstack.common import strutils PARAMETER_KEYS = ( @@ -251,7 +253,7 @@ class Parameter(object): if self.hidden(): return '******' else: - return str(value) + return strutils.safe_encode(six.text_type(value)) class NumberParam(Parameter): diff --git a/heat/tests/test_parameters.py b/heat/tests/test_parameters.py index d91343dc2c..8413fd4e0b 100644 --- a/heat/tests/test_parameters.py +++ b/heat/tests/test_parameters.py @@ -164,6 +164,11 @@ class ParameterTest(testtools.TestCase): p = self.new_parameter('p', schema, 'bar') self.assertEqual('bar', p.value()) + def test_string_value_unicode(self): + schema = {'Type': 'String'} + p = self.new_parameter('p', schema, u'test\u2665') + self.assertEqual(u'test\u2665', p.value()) + def test_string_value_list_bad(self): schema = {'Type': 'String', 'ConstraintDescription': 'wibble', @@ -375,13 +380,17 @@ class ParametersTest(testtools.TestCase): def test_map_str(self): template = {'Parameters': {'Foo': {'Type': 'String'}, - 'Bar': {'Type': 'Number'}}} + 'Bar': {'Type': 'Number'}, + 'Uni': {'Type': 'String'}}} stack_name = 'test_params' params = self.new_parameters(stack_name, template, - {'Foo': 'foo', 'Bar': '42'}) + {'Foo': 'foo', + 'Bar': '42', + 'Uni': u'test\u2665'}) expected = {'Foo': 'foo', 'Bar': '42', + 'Uni': 'test\xe2\x99\xa5', 'AWS::Region': 'ap-southeast-1', 'AWS::StackId': 'arn:openstack:heat:::stacks/{0}/{1}'.format(