[Checkins] SVN: zope.publisher/branches/3.4/ 3.4.3 (unreleased)

Andreas Jung andreas at andreas-jung.com
Thu Jul 31 03:29:30 EDT 2008


Log message for revision 89074:
  
  3.4.3 (unreleased)
  ------------------
  
  _ LP #253362: better dealing with malformed HTTP_ACCEPT_CHARSET headers
  

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

-=-
Modified: zope.publisher/branches/3.4/CHANGES.txt
===================================================================
--- zope.publisher/branches/3.4/CHANGES.txt	2008-07-31 07:20:41 UTC (rev 89073)
+++ zope.publisher/branches/3.4/CHANGES.txt	2008-07-31 07:29:29 UTC (rev 89074)
@@ -4,6 +4,8 @@
 3.4.3 (unreleased)
 ------------------
 
+_ LP #253362: better dealing with malformed HTTP_ACCEPT_CHARSET headers
+
 3.4.2 (2007-12-07)
 ------------------
 

Modified: zope.publisher/branches/3.4/src/zope/publisher/http.py
===================================================================
--- zope.publisher/branches/3.4/src/zope/publisher/http.py	2008-07-31 07:20:41 UTC (rev 89073)
+++ zope.publisher/branches/3.4/src/zope/publisher/http.py	2008-07-31 07:29:29 UTC (rev 89074)
@@ -928,7 +928,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/branches/3.4/src/zope/publisher/tests/test_httpcharsets.py
===================================================================
--- zope.publisher/branches/3.4/src/zope/publisher/tests/test_httpcharsets.py	2008-07-31 07:20:41 UTC (rev 89073)
+++ zope.publisher/branches/3.4/src/zope/publisher/tests/test_httpcharsets.py	2008-07-31 07:29:29 UTC (rev 89074)
@@ -88,6 +88,13 @@
         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