From a52cc1c0888c2cedb07b2c0619c1a92a2f6e2c40 Mon Sep 17 00:00:00 2001 From: Josh Mize Date: Mon, 9 Sep 2013 11:48:56 -0500 Subject: [PATCH] Fixed #21078 -- Handled additional bad Accept-Language header --- django/utils/translation/trans_real.py | 5 ++++- tests/i18n/tests.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index a6b7eaa489..c7b41fa373 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -668,7 +668,10 @@ def parse_accept_lang_header(lang_string): if first: return [] if priority: - priority = float(priority) + try: + priority = float(priority) + except ValueError: + return [] if not priority: # if priority is 0.0 at this point make it 1.0 priority = 1.0 result.append((lang, priority)) diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index c18c88cad3..f482dba3bb 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -849,6 +849,7 @@ class MiscTests(TransRealMixin, TestCase): self.assertEqual([], p('de;q=0.a')) self.assertEqual([], p('12-345')) self.assertEqual([], p('')) + self.assertEqual([], p('en; q=1,')) def test_parse_literal_http_header(self): """