[Checkins] SVN: zope.publisher/trunk/src/zope/publisher/ Return UTF-8 if ACCEPT_CHARSET is not set or empty. W3C spec is the browser can accept anything and UTF-8 is the only sane default.

Charlie Clark charlie at begeistert.org
Tue Oct 26 10:15:00 EDT 2010


Log message for revision 117902:
  Return UTF-8 if ACCEPT_CHARSET is not set or empty. W3C spec is the browser can accept anything and UTF-8 is the only sane default.

Changed:
  U   zope.publisher/trunk/src/zope/publisher/http.py
  U   zope.publisher/trunk/src/zope/publisher/tests/test_httpcharsets.py

-=-
Modified: zope.publisher/trunk/src/zope/publisher/http.py
===================================================================
--- zope.publisher/trunk/src/zope/publisher/http.py	2010-10-26 13:54:41 UTC (rev 117901)
+++ zope.publisher/trunk/src/zope/publisher/http.py	2010-10-26 14:14:59 UTC (rev 117902)
@@ -1000,6 +1000,8 @@
         charsets = [charset for quality, charset in charsets]
         if sawstar and 'utf-8' not in charsets:
             charsets.insert(0, 'utf-8')
+        elif charsets == []:
+            charsets = ['utf-8']
         return charsets
 
 

Modified: zope.publisher/trunk/src/zope/publisher/tests/test_httpcharsets.py
===================================================================
--- zope.publisher/trunk/src/zope/publisher/tests/test_httpcharsets.py	2010-10-26 13:54:41 UTC (rev 117901)
+++ zope.publisher/trunk/src/zope/publisher/tests/test_httpcharsets.py	2010-10-26 14:14:59 UTC (rev 117902)
@@ -69,22 +69,20 @@
                          ['utf-8', 'iso-8859-1', '*'])
 
     def testNoHTTP_ACCEPT_CHARSET(self):
-        # If the client doesn't provide a HTTP_ACCEPT_CHARSET, it should
-        # accept any charset
+        # If the client doesn't provide a HTTP_ACCEPT_CHARSET, it can
+        # accept any charset.
         request = {}
         browser_charsets = HTTPCharsets(request)
         self.assertEqual(list(browser_charsets.getPreferredCharsets()),
-                         [])
+                         ['utf-8'])
 
     def testTrivialHTTP_ACCEPT_CHARSET(self):
-        # If the client provides a trivial HTTP_ACCEPT_CHARSET, it should
-        # accept any charset (this test is aimed at Zope 2's handling
-        # of request queries for entries starting with HTTP_
-        # See: https://bugs.launchpad.net/zope2/+bug/143873
+        # If the client provides a trivial HTTP_ACCEPT_CHARSET, it can
+        # accept any charset
         request = {'HTTP_ACCEPT_CHARSET': ''}
         browser_charsets = HTTPCharsets(request)
         self.assertEqual(list(browser_charsets.getPreferredCharsets()),
-                         [])
+                         ['utf-8'])
 
     def testMalformedHTTP_ACCEPT_CHARSET(self):
         """ Test for Launchpad #253362 """



More information about the checkins mailing list