[Zope3-checkins] SVN: Zope3/branches/3.3/src/zope/publisher/ - LP
#253362: better dealing with malformed HTTP_ACCEPT_CHARSET headers
Andreas Jung
andreas at andreas-jung.com
Tue Aug 5 14:57:13 EDT 2008
Log message for revision 89417:
- LP #253362: better dealing with malformed HTTP_ACCEPT_CHARSET headers
Changed:
U Zope3/branches/3.3/src/zope/publisher/http.py
U Zope3/branches/3.3/src/zope/publisher/tests/test_httpcharsets.py
-=-
Modified: Zope3/branches/3.3/src/zope/publisher/http.py
===================================================================
--- Zope3/branches/3.3/src/zope/publisher/http.py 2008-08-05 18:27:55 UTC (rev 89416)
+++ Zope3/branches/3.3/src/zope/publisher/http.py 2008-08-05 18:57:12 UTC (rev 89417)
@@ -998,7 +998,10 @@
charset = charset.strip().lower()
if charset:
if ';' in charset:
- charset, quality = charset.split(';')
+ try:
+ charset, quality = charset.split(';')
+ except ValueError:
+ continue
if not quality.startswith('q='):
# not a quality parameter
quality = 1.0
Modified: Zope3/branches/3.3/src/zope/publisher/tests/test_httpcharsets.py
===================================================================
--- Zope3/branches/3.3/src/zope/publisher/tests/test_httpcharsets.py 2008-08-05 18:27:55 UTC (rev 89416)
+++ Zope3/branches/3.3/src/zope/publisher/tests/test_httpcharsets.py 2008-08-05 18:57:12 UTC (rev 89417)
@@ -78,7 +78,12 @@
self.assertEqual(list(browser_charsets.getPreferredCharsets()),
[])
-
+ def testMalformedHTTP_ACCEPT_CHARSET(self):
+ """ Test for Launchpad #253362 """
+ request = {'HTTP_ACCEPT_CHARSET': 'utf-8;q=0.7,iso-8859-1;q=0.2*;q=0.1'}
+ browser_charsets = HTTPCharsets(request)
+ self.assertEqual(list(browser_charsets.getPreferredCharsets()),
+ ['utf-8', 'iso-8859-1'])
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(HTTPCharsetTest)
More information about the Zope3-Checkins
mailing list