[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/publisher/ Merge revision 25999 from trunk: use utf-8 as default encoding when

Philipp von Weitershausen philikon at philikon.de
Tue Jun 29 13:35:41 EDT 2004


Log message for revision 26000:
Merge revision 25999 from trunk: use utf-8 as default encoding when
interpreting request form data.



-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/publisher/browser.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/publisher/browser.py	2004-06-29 17:26:35 UTC (rev 25999)
+++ Zope3/branches/ZopeX3-3.0/src/zope/publisher/browser.py	2004-06-29 17:35:41 UTC (rev 26000)
@@ -229,7 +229,7 @@
         """Try to decode the text using one of the available charsets."""
         if self.charsets is None:
             envadapter = IUserPreferredCharsets(self)
-            self.charsets = envadapter.getPreferredCharsets()
+            self.charsets = envadapter.getPreferredCharsets() or ['utf-8']
         for charset in self.charsets:
             try:
                 text = unicode(text, charset)

Modified: Zope3/branches/ZopeX3-3.0/src/zope/publisher/tests/test_browserrequest.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/publisher/tests/test_browserrequest.py	2004-06-29 17:26:35 UTC (rev 25999)
+++ Zope3/branches/ZopeX3-3.0/src/zope/publisher/tests/test_browserrequest.py	2004-06-29 17:35:41 UTC (rev 26000)
@@ -207,6 +207,20 @@
         self.assertEqual(request.form,
                          {u'a':u'5', u'b':6})
 
+    def testFormNoEncodingUsesUTF8(self):
+        encoded = 'K\xc3\x83\xc2\xb6hlerstra\xc3\x83\xc2\x9fe'
+        extra = {
+            # if nothing else is specified, form data should be
+            # interpreted as UTF-8, as this stub query string is
+            'QUERY_STRING': 'a=5&b:int=6&street=' + encoded
+            }
+        request = self._createRequest(extra)
+        # many mainstream browsers do not send HTTP_ACCEPT_CHARSET
+        del request._environ['HTTP_ACCEPT_CHARSET']
+        publish(request)
+        self.assert_(isinstance(request.form[u'street'], unicode))
+        self.assertEqual(unicode(encoded, 'utf-8'), request.form['street'])
+
     def testFormListTypes(self):
         extra = {'QUERY_STRING':'a:list=5&a:list=6&b=1'}
         request = self._createRequest(extra)



More information about the Zope3-Checkins mailing list