[Checkins] SVN: zope.publisher/branches/3.4/src/zope/publisher/ - fix for LP #273296

John Murphy jackie at zope.com
Mon Sep 22 16:18:56 EDT 2008


Log message for revision 91375:
  - fix for LP #273296
  
  

Changed:
  U   zope.publisher/branches/3.4/src/zope/publisher/browser.py
  U   zope.publisher/branches/3.4/src/zope/publisher/tests/test_http.py

-=-
Modified: zope.publisher/branches/3.4/src/zope/publisher/browser.py
===================================================================
--- zope.publisher/branches/3.4/src/zope/publisher/browser.py	2008-09-22 20:17:19 UTC (rev 91374)
+++ zope.publisher/branches/3.4/src/zope/publisher/browser.py	2008-09-22 20:18:56 UTC (rev 91375)
@@ -778,7 +778,11 @@
                 q = l[1]
                 if q.startswith('q='):
                     q = q.split('=', 2)[1]
-                    quality = float(q)
+                    try:
+                        quality = float(q)
+                    except ValueError:
+                        # malformed quality value, skip it.
+                        continue
 
             if quality == 1.0:
                 # ... but we use 1.9 - 0.001 * position to

Modified: zope.publisher/branches/3.4/src/zope/publisher/tests/test_http.py
===================================================================
--- zope.publisher/branches/3.4/src/zope/publisher/tests/test_http.py	2008-09-22 20:17:19 UTC (rev 91374)
+++ zope.publisher/branches/3.4/src/zope/publisher/tests/test_http.py	2008-09-22 20:18:56 UTC (rev 91375)
@@ -322,6 +322,22 @@
         eq(locale.id.territory, None)
         eq(locale.id.variant, None)
 
+        # Now test for improper quality value, should ignore the header
+        req = self._createRequest({'HTTP_ACCEPT_LANGUAGE': 'en;q=xx'})
+        locale = req.locale
+        unless(ILocale.providedBy(locale))
+        eq(locale.id.language, None)
+        eq(locale.id.territory, None)
+        eq(locale.id.variant, None)
+
+        # Now test for very improper quality value, should ignore the header
+        req = self._createRequest({'HTTP_ACCEPT_LANGUAGE': 'asdf;qwer'})
+        locale = req.locale
+        unless(ILocale.providedBy(locale))
+        eq(locale.id.language, None)
+        eq(locale.id.territory, None)
+        eq(locale.id.variant, None)
+
         from zope.component.testing import tearDown
         tearDown()
 



More information about the Checkins mailing list