[Zope3-checkins] SVN: Zope3/trunk/src/zope/publisher/ Fix
http://www.zope.org/Collectors/Zope3-dev/587,
make sure that utf-8 is
Bjorn Tillenius
bjorn.tillenius at gmail.com
Fri Apr 21 08:51:14 EDT 2006
Log message for revision 67209:
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/trunk/src/zope/publisher/http.py
U Zope3/trunk/src/zope/publisher/tests/test_httpcharsets.py
-=-
Modified: Zope3/trunk/src/zope/publisher/http.py
===================================================================
--- Zope3/trunk/src/zope/publisher/http.py 2006-04-21 12:30:55 UTC (rev 67208)
+++ Zope3/trunk/src/zope/publisher/http.py 2006-04-21 12:51:14 UTC (rev 67209)
@@ -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/trunk/src/zope/publisher/tests/test_httpcharsets.py
===================================================================
--- Zope3/trunk/src/zope/publisher/tests/test_httpcharsets.py 2006-04-21 12:30:55 UTC (rev 67208)
+++ Zope3/trunk/src/zope/publisher/tests/test_httpcharsets.py 2006-04-21 12:51:14 UTC (rev 67209)
@@ -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