[Checkins] SVN: zope.publisher/branches/acceptlang-bugfix/src/zope/publisher/ - bugfix and test

John Murphy jackie at zope.com
Mon Sep 22 15:41:11 EDT 2008


Log message for revision 91366:
  - bugfix and test
  
  

Changed:
  U   zope.publisher/branches/acceptlang-bugfix/src/zope/publisher/browser.py
  U   zope.publisher/branches/acceptlang-bugfix/src/zope/publisher/tests/test_http.py

-=-
Modified: zope.publisher/branches/acceptlang-bugfix/src/zope/publisher/browser.py
===================================================================
--- zope.publisher/branches/acceptlang-bugfix/src/zope/publisher/browser.py	2008-09-22 17:36:08 UTC (rev 91365)
+++ zope.publisher/branches/acceptlang-bugfix/src/zope/publisher/browser.py	2008-09-22 19:41:09 UTC (rev 91366)
@@ -790,7 +790,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/acceptlang-bugfix/src/zope/publisher/tests/test_http.py
===================================================================
--- zope.publisher/branches/acceptlang-bugfix/src/zope/publisher/tests/test_http.py	2008-09-22 17:36:08 UTC (rev 91365)
+++ zope.publisher/branches/acceptlang-bugfix/src/zope/publisher/tests/test_http.py	2008-09-22 19:41:09 UTC (rev 91366)
@@ -343,6 +343,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