Author: jezdez
Date: 2011-06-26 09:51:54 -0700 (Sun, 26 Jun 2011)
New Revision: 16457

Modified:
   django/trunk/django/utils/translation/trans_real.py
   django/trunk/tests/regressiontests/i18n/tests.py
Log:
Fixed #16322 -- Fixed Accept-Language parsing to allow spaces around 
semicolons. Thanks, Max Arnold.

Modified: django/trunk/django/utils/translation/trans_real.py
===================================================================
--- django/trunk/django/utils/translation/trans_real.py 2011-06-26 16:51:46 UTC 
(rev 16456)
+++ django/trunk/django/utils/translation/trans_real.py 2011-06-26 16:51:54 UTC 
(rev 16457)
@@ -30,9 +30,9 @@
 
 # Format of Accept-Language header values. From RFC 2616, section 14.4 and 3.9.
 accept_language_re = re.compile(r'''
-        ([A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*|\*)   # "en", "en-au", "x-y-z", "*"
-        (?:;q=(0(?:\.\d{,3})?|1(?:.0{,3})?))?   # Optional "q=1.00", "q=0.8"
-        (?:\s*,\s*|$)                            # Multiple accepts per header.
+        ([A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*|\*)         # "en", "en-au", 
"x-y-z", "*"
+        (?:\s*;\s*q=(0(?:\.\d{,3})?|1(?:.0{,3})?))?   # Optional "q=1.00", 
"q=0.8"
+        (?:\s*,\s*|$)                                 # Multiple accepts per 
header.
         ''', re.VERBOSE)
 
 language_code_prefix_re = re.compile(r'^/([\w-]+)/')

Modified: django/trunk/tests/regressiontests/i18n/tests.py
===================================================================
--- django/trunk/tests/regressiontests/i18n/tests.py    2011-06-26 16:51:46 UTC 
(rev 16456)
+++ django/trunk/tests/regressiontests/i18n/tests.py    2011-06-26 16:51:54 UTC 
(rev 16457)
@@ -516,6 +516,7 @@
         self.assertEqual([('de', 1.0), ('en-au', 0.75), ('en-us', 0.5), ('en', 
0.25), ('es', 0.125), ('fa', 0.125)], 
p('de,en-au;q=0.75,en-us;q=0.5,en;q=0.25,es;q=0.125,fa;q=0.125'))
         self.assertEqual([('*', 1.0)], p('*'))
         self.assertEqual([('de', 1.0)], p('de;q=0.'))
+        self.assertEqual([('en', 1.0), ('*', 0.5)], p('en; q=1.0, * ; q=0.5'))
         self.assertEqual([], p(''))
 
         # Bad headers; should always return [].

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to