Skip to content

Commit ab655fd

Browse files
committed
Fixed unicode issues for XML template with Python 2
1 parent afa8622 commit ab655fd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

roundup/cgi/TAL/XMLParser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class XMLParser:
4949

5050
def __init__(self, encoding=None):
5151
self.parser = p = self.createParser()
52+
# Make sure we don't get fed unicode strings in Python 2 as we
53+
# can't handle those
54+
if hasattr(self.parser, 'returns_unicode'):
55+
self.parser.returns_unicode = False
5256
if self.ordered_attributes:
5357
try:
5458
self.parser.ordered_attributes = self.ordered_attributes

test/test_cgi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,16 @@ def hasPermission(s, p, classname=None, d=None, e=None, **kw):
807807
</html>
808808
""".strip ())
809809

810+
def testXMLTemplate(self):
811+
page_template = """<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:tal="http://xml.zope.org/namespaces/tal" xmlns:metal="http://xml.zope.org/namespaces/metal"></feed>"""
812+
pt = RoundupPageTemplate()
813+
pt.pt_edit(page_template, 'application/xml')
814+
815+
cl = self.setupClient({ }, 'issue',
816+
env_addon = {'HTTP_REFERER': 'http://whoami.com/path/'})
817+
out = pt.render(cl, 'issue', MockNull())
818+
self.assertEquals(out, '<?xml version="1.0" encoding="UTF-8"?><feed\n xmlns="http://www.w3.org/2005/Atom"/>\n')
819+
810820
def testCsrfProtection(self):
811821
# need to set SENDMAILDEBUG to prevent
812822
# downstream issue when email is sent on successful

0 commit comments

Comments
 (0)