Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16322 -- Fixed Accept-Language parsing to allow spaces around …

…semicolons. Thanks, Max Arnold.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16457 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 352b7ffaf039b3b7b112dd60a690101ecec70cf2 1 parent 4a10338
Jannis Leidel authored June 26, 2011
6  django/utils/translation/trans_real.py
@@ -30,9 +30,9 @@
30 30
 
31 31
 # Format of Accept-Language header values. From RFC 2616, section 14.4 and 3.9.
32 32
 accept_language_re = re.compile(r'''
33  
-        ([A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*|\*)   # "en", "en-au", "x-y-z", "*"
34  
-        (?:;q=(0(?:\.\d{,3})?|1(?:.0{,3})?))?   # Optional "q=1.00", "q=0.8"
35  
-        (?:\s*,\s*|$)                            # Multiple accepts per header.
  33
+        ([A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*|\*)         # "en", "en-au", "x-y-z", "*"
  34
+        (?:\s*;\s*q=(0(?:\.\d{,3})?|1(?:.0{,3})?))?   # Optional "q=1.00", "q=0.8"
  35
+        (?:\s*,\s*|$)                                 # Multiple accepts per header.
36 36
         ''', re.VERBOSE)
37 37
 
38 38
 language_code_prefix_re = re.compile(r'^/([\w-]+)/')
1  tests/regressiontests/i18n/tests.py
@@ -516,6 +516,7 @@ def test_parse_spec_http_header(self):
516 516
         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'))
517 517
         self.assertEqual([('*', 1.0)], p('*'))
518 518
         self.assertEqual([('de', 1.0)], p('de;q=0.'))
  519
+        self.assertEqual([('en', 1.0), ('*', 0.5)], p('en; q=1.0, * ; q=0.5'))
519 520
         self.assertEqual([], p(''))
520 521
 
521 522
         # Bad headers; should always return [].

0 notes on commit 352b7ff

Please sign in to comment.
Something went wrong with that request. Please try again.