Fixed #26744 -- Fixed a typo in regex for Accept-Language header parsing.

This commit is contained in:
Vytis Banaitis 2016-06-12 04:32:56 +03:00 committed by Tim Graham
parent 6928ad184e
commit f1b38842af
2 changed files with 4 additions and 6 deletions

View File

@ -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))

View File

@ -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):
"""