[Checkins] SVN: zope.publisher/trunk/ - LP #253362: dealing more nicely with malformed HTTP_ACCEPT_CHARSET headers

Andreas Jung andreas at andreas-jung.com
Thu Jul 31 03:18:04 EDT 2008


Log message for revision 89072:
  
  - LP #253362: dealing more nicely with malformed HTTP_ACCEPT_CHARSET headers
    within getPreferredCharsets().
  
  

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

-=-
Modified: zope.publisher/trunk/CHANGES.txt
===================================================================
--- zope.publisher/trunk/CHANGES.txt	2008-07-31 01:06:12 UTC (rev 89071)
+++ zope.publisher/trunk/CHANGES.txt	2008-07-31 07:17:59 UTC (rev 89072)
@@ -1,6 +1,15 @@
 CHANGES
 =======
 
+3.5.4 (unreleased)
+------------------
+
+Bugs fixed:
+
+- LP #253362: dealing more nicely with malformed HTTP_ACCEPT_CHARSET headers
+  within getPreferredCharsets().
+
+
 3.5.3 (2008-06-20)
 ------------------
 

Modified: zope.publisher/trunk/src/zope/publisher/http.py
===================================================================
--- zope.publisher/trunk/src/zope/publisher/http.py	2008-07-31 01:06:12 UTC (rev 89071)
+++ zope.publisher/trunk/src/zope/publisher/http.py	2008-07-31 07:17:59 UTC (rev 89072)
@@ -929,7 +929,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: zope.publisher/trunk/src/zope/publisher/tests/test_httpcharsets.py
===================================================================
--- zope.publisher/trunk/src/zope/publisher/tests/test_httpcharsets.py	2008-07-31 01:06:12 UTC (rev 89071)
+++ zope.publisher/trunk/src/zope/publisher/tests/test_httpcharsets.py	2008-07-31 07:17:59 UTC (rev 89072)
@@ -88,7 +88,15 @@
         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 Checkins mailing list