[Zope3-checkins] SVN: Zope3/branches/3.2/ Backport bug fix from trunk:

Bjorn Tillenius bjorn.tillenius at gmail.com
Fri Apr 21 08:57:49 EDT 2006


Log message for revision 67212:
  Backport bug fix from trunk:
  
  ------------------------------------------------------------------------
  r67209 | BjornT | 2006-04-21 15:51:14 +0300 (Fri, 21 Apr 2006) | 4 lines
  
  Fix http://www.zope.org/Collectors/Zope3-dev/587, make sure that utf-8 is
  chosen as the preferred encoding if '*' is present in the Accept-Charset
  header.
  
  ------------------------------------------------------------------------
  

Changed:
  U   Zope3/branches/3.2/doc/CHANGES.txt
  U   Zope3/branches/3.2/src/zope/publisher/http.py
  U   Zope3/branches/3.2/src/zope/publisher/tests/test_httpcharsets.py

-=-
Modified: Zope3/branches/3.2/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.2/doc/CHANGES.txt	2006-04-21 12:55:55 UTC (rev 67211)
+++ Zope3/branches/3.2/doc/CHANGES.txt	2006-04-21 12:57:48 UTC (rev 67212)
@@ -30,7 +30,10 @@
         Content-Length header after inserting a <base> tag, causing
         pages to be truncated in the browser.
 
+      - Fixed issue 587, make sure that utf-8 is chosen if the
+        Accept-Charset header contains '*'.
 
+
   Zope 3.2.1 (2006/03/26)
 
     Bug fixes

Modified: Zope3/branches/3.2/src/zope/publisher/http.py
===================================================================
--- Zope3/branches/3.2/src/zope/publisher/http.py	2006-04-21 12:55:55 UTC (rev 67211)
+++ Zope3/branches/3.2/src/zope/publisher/http.py	2006-04-21 12:57:48 UTC (rev 67212)
@@ -1020,7 +1020,10 @@
         # different ranges, like providing a French-Chinese dictionary, it is
         # always good to use UTF-8.
         charsets.sort(sort_charsets)
-        return [c[1] for c in charsets]
+        charsets = [charset for quality, charset in charsets]
+        if sawstar and 'utf-8' not in charsets:
+            charsets.insert(0, 'utf-8')
+        return charsets
 
 
 def getCharsetUsingRequest(request):

Modified: Zope3/branches/3.2/src/zope/publisher/tests/test_httpcharsets.py
===================================================================
--- Zope3/branches/3.2/src/zope/publisher/tests/test_httpcharsets.py	2006-04-21 12:55:55 UTC (rev 67211)
+++ Zope3/branches/3.2/src/zope/publisher/tests/test_httpcharsets.py	2006-04-21 12:57:48 UTC (rev 67212)
@@ -53,6 +53,23 @@
         self.assertEqual(list(browser_charsets.getPreferredCharsets()),
                          ['iso-8859-1', 'utf-16'])
 
+    def testStarNoUtf8(self):
+        # If '*' is in HTTP_ACCEPT_CHARSET, but 'utf-8' isn't, we insert
+        # utf-8 in the list, since we prefer that over any other #
+        # charset.
+        request = {'HTTP_ACCEPT_CHARSET': 'ISO-8859-1, *'}
+        browser_charsets = HTTPCharsets(request)
+        self.assertEqual(list(browser_charsets.getPreferredCharsets()),
+                         ['utf-8', 'iso-8859-1', '*'])
+
+    def testStarAndUtf8(self):
+        # If '*' and 'utf-8' are in HTTP_ACCEPT_CHARSET, we won't insert
+        # an extra 'utf-8'.
+        request = {'HTTP_ACCEPT_CHARSET': 'ISO-8859-1, utf-8, *'}
+        browser_charsets = HTTPCharsets(request)
+        self.assertEqual(list(browser_charsets.getPreferredCharsets()),
+                         ['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



More information about the Zope3-Checkins mailing list