mirror of https://github.com/django/django.git
Fixed #26744 -- Fixed a typo in regex for Accept-Language header parsing.
This commit is contained in:
parent
6928ad184e
commit
f1b38842af
|
@ -39,7 +39,7 @@ CONTEXT_SEPARATOR = "\x04"
|
|||
# and RFC 3066, section 2.1
|
||||
accept_language_re = re.compile(r'''
|
||||
([A-Za-z]{1,8}(?:-[A-Za-z0-9]{1,8})*|\*) # "en", "en-au", "x-y-z", "es-419", "*"
|
||||
(?:\s*;\s*q=(0(?:\.\d{,3})?|1(?:.0{,3})?))? # Optional "q=1.00", "q=0.8"
|
||||
(?:\s*;\s*q=(0(?:\.\d{,3})?|1(?:\.0{,3})?))? # Optional "q=1.00", "q=0.8"
|
||||
(?:\s*,\s*|$) # Multiple accepts per header.
|
||||
''', re.VERBOSE)
|
||||
|
||||
|
@ -790,10 +790,7 @@ def parse_accept_lang_header(lang_string):
|
|||
if first:
|
||||
return []
|
||||
if priority:
|
||||
try:
|
||||
priority = float(priority)
|
||||
except ValueError:
|
||||
return []
|
||||
priority = float(priority)
|
||||
if not priority: # if priority is 0.0 at this point make it 1.0
|
||||
priority = 1.0
|
||||
result.append((lang, priority))
|
||||
|
|
|
@ -1317,6 +1317,7 @@ class MiscTests(SimpleTestCase):
|
|||
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([('en', 1.0)], p('en; q=1,'))
|
||||
self.assertEqual([], p(''))
|
||||
|
||||
# Bad headers; should always return [].
|
||||
|
@ -1336,7 +1337,7 @@ class MiscTests(SimpleTestCase):
|
|||
self.assertEqual([], p('de;q=0.a'))
|
||||
self.assertEqual([], p('12-345'))
|
||||
self.assertEqual([], p(''))
|
||||
self.assertEqual([], p('en; q=1,'))
|
||||
self.assertEqual([], p('en;q=1e0'))
|
||||
|
||||
def test_parse_literal_http_header(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue