[Zope3-checkins] SVN: Zope3/trunk/ Fix collector issue #264: Substituting a Unicode value containing non-ASCII

Fred L. Drake, Jr. fdrake at gmail.com
Tue Aug 31 19:02:38 EDT 2004


Log message for revision 27372:
  Fix collector issue #264: Substituting a Unicode value containing non-ASCII
  text into a translated string caused a UnicodeDecodeError.
  


Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/tal/talinterpreter.py
  U   Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py


-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2004-08-31 22:57:40 UTC (rev 27371)
+++ Zope3/trunk/doc/CHANGES.txt	2004-08-31 23:02:38 UTC (rev 27372)
@@ -63,6 +63,10 @@
 
     Bug Fixes
 
+      - Fixed issue 264.  Substituting a Unicode value containing
+        non-ASCII text into a translated string caused a
+        UnicodeDecodeError.
+
       - Fixed issue 228.
 
       - Fixed issue 248.  Path expressions in page templates that

Modified: Zope3/trunk/src/zope/tal/talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/talinterpreter.py	2004-08-31 22:57:40 UTC (rev 27371)
+++ Zope3/trunk/src/zope/tal/talinterpreter.py	2004-08-31 23:02:38 UTC (rev 27372)
@@ -605,7 +605,7 @@
                 value = self.engine.translate(value)
 
             if not structure:
-                value = cgi.escape(str(value))
+                value = cgi.escape(unicode(value))
 
         # Either the i18n:name tag is nested inside an i18n:translate in which
         # case the last item on the stack has the i18n dictionary and string

Modified: Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py	2004-08-31 22:57:40 UTC (rev 27371)
+++ Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py	2004-08-31 23:02:38 UTC (rev 27372)
@@ -216,7 +216,15 @@
             '<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n',
             result.getvalue())
 
+    def test_for_handling_unicode_vars(self):
+        # Make sure that non-ASCII Unicode is substituted correctly.
+        # http://collector.zope.org/Zope3-dev/264
+        program, macros = self._compile(
+            "<div i18n:translate='' tal:define='bar python:unichr(0xC0)'>"
+            "Foo <span tal:replace='bar' i18n:name='bar' /></div>")
+        self._check(program, u"<div>FOO \u00C0</div>\n")
 
+
 class ScriptTestCase(TestCaseBase):
 
     def setUp(self):



More information about the Zope3-Checkins mailing list