Fix XML UnicodeEncode serialization error
The generic Nova XMLSerializer code will currently attempt to cast to str the value for all leaf nodes. This patch ensures that no attempt is made to convert unicode which can cause a UnicodeEncode error. We don't need to convert unicode for XML text and regardless we encode to UTF-8 at a later point. Change-Id: I8135d2b9a67db62b0eafdd301b7fdb67a5dd72cc Closes-Bug: #1279172 (cherry picked from commit53fe869631
) (cherry picked from commit3136cfc11f
)
This commit is contained in:
parent
d884d3235b
commit
7cdb643cb3
|
@ -435,7 +435,9 @@ class XMLDictSerializer(DictSerializer):
|
|||
result.appendChild(node)
|
||||
else:
|
||||
# Type is atom
|
||||
node = doc.createTextNode(str(data))
|
||||
if not isinstance(data, six.string_types):
|
||||
data = six.text_type(data)
|
||||
node = doc.createTextNode(data)
|
||||
result.appendChild(node)
|
||||
return result
|
||||
|
||||
|
|
|
@ -221,6 +221,14 @@ class XMLDictSerializerTest(test.NoDBTestCase):
|
|||
result = result.replace('\n', '').replace(' ', '')
|
||||
self.assertEqual(result, expected_xml)
|
||||
|
||||
def test_xml_contains_unicode(self):
|
||||
input_dict = dict(test=u'\u89e3\u7801')
|
||||
expected_xml = '<test>\xe8\xa7\xa3\xe7\xa0\x81</test>'
|
||||
serializer = wsgi.XMLDictSerializer()
|
||||
result = serializer.serialize(input_dict)
|
||||
result = result.replace('\n', '').replace(' ', '')
|
||||
self.assertEqual(expected_xml, result)
|
||||
|
||||
|
||||
class JSONDictSerializerTest(test.NoDBTestCase):
|
||||
def test_json(self):
|
||||
|
|
Loading…
Reference in New Issue