Commit 807eae72 authored by Andreas Jung's avatar Andreas Jung

- fix for collector #2339 (unicode decode error when using the 'structure'

  directive
- ZopeContext: added evaluateStructure() method in order to catch 
  UnicodeDecodeErrors and handle them properly using the unicode conflict
  resolver
parent d56863d1
......@@ -217,11 +217,19 @@ class ZopeContext(Context):
return value
return bool(value)
def evaluateStructure(self, expr):
text = super(ZopeContext, self).evaluateStructure(expr)
return self._handleText(text, expr)
def evaluateText(self, expr):
""" customized version in order to get rid of unicode
errors for all and ever
"""
text = self.evaluate(expr)
return self._handleText(text, expr)
def _handleText(self, text, expr):
if text is self.getDefault() or text is None:
# XXX: should be unicode???
......
......@@ -121,6 +121,16 @@ class ZPTUnicodeEncodingConflictResolution(ZopeTestCase):
result = zpt.pt_render()
self.assertEqual(result.startswith(unicode('<div></div>', 'iso-8859-15')), False)
def testStructureWithAccentedChars(self):
manage_addPageTemplate(self.app, 'test',
text='<div tal:content="structure python: %s" />' % "''",
encoding='iso-8859-15')
zpt = self.app['test']
self.app.REQUEST.set('HTTP_ACCEPT_CHARSET', 'iso-8859-15,utf-8')
self.app.REQUEST.set('data', unicode('', 'iso-8859-15').encode('utf-8'))
result = zpt.pt_render()
self.assertEqual(result.startswith(unicode('<div></div>', 'iso-8859-15')), True)
class ZopePageTemplateFileTests(ZopeTestCase):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment