Fixed #26746 -- Fixed handling of zero priority in Accept-Language header parsing.

This commit is contained in:
Vytis Banaitis 2016-06-13 14:58:25 +03:00 committed by Tim Graham
parent f1b38842af
commit 57eb17b8c7
2 changed files with 2 additions and 2 deletions

View File

@ -791,7 +791,7 @@ def parse_accept_lang_header(lang_string):
return [] return []
if priority: if priority:
priority = float(priority) priority = float(priority)
if not priority: # if priority is 0.0 at this point make it 1.0 else:
priority = 1.0 priority = 1.0
result.append((lang, priority)) result.append((lang, priority))
result.sort(key=lambda k: k[1], reverse=True) result.sort(key=lambda k: k[1], reverse=True)

View File

@ -1315,7 +1315,7 @@ class MiscTests(SimpleTestCase):
p('de,en-au;q=0.75,en-us;q=0.5,en;q=0.25,es;q=0.125,fa;q=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([('*', 1.0)], p('*'))
self.assertEqual([('de', 1.0)], p('de;q=0.')) self.assertEqual([('de', 0.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), ('*', 0.5)], p('en; q=1.0, * ; q=0.5'))
self.assertEqual([('en', 1.0)], p('en; q=1,')) self.assertEqual([('en', 1.0)], p('en; q=1,'))
self.assertEqual([], p('')) self.assertEqual([], p(''))