From e6b34193c5c7d117ededdab04bb16caf8864f07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= Date: Sun, 21 Oct 2012 01:25:35 +0200 Subject: [PATCH] Fixed #19142 -- Language codes can include numbers (RFC 3066). --- django/utils/translation/trans_real.py | 5 +++-- tests/regressiontests/i18n/tests.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index cce2a8cb864..9e94840ee0b 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -30,9 +30,10 @@ _accepted = {} # magic gettext number to separate context from message CONTEXT_SEPARATOR = "\x04" -# Format of Accept-Language header values. From RFC 2616, section 14.4 and 3.9. +# Format of Accept-Language header values. From RFC 2616, section 14.4 and 3.9 +# and RFC 3066, section 2.1 accept_language_re = re.compile(r''' - ([A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*|\*) # "en", "en-au", "x-y-z", "*" + ([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*|$) # Multiple accepts per header. ''', re.VERBOSE) diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index bce3d617d23..45471a9678c 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -715,6 +715,7 @@ class MiscTests(TestCase): # Good headers. self.assertEqual([('de', 1.0)], p('de')) self.assertEqual([('en-AU', 1.0)], p('en-AU')) + self.assertEqual([('es-419', 1.0)], p('es-419')) self.assertEqual([('*', 1.0)], p('*;q=1.00')) self.assertEqual([('en-AU', 0.123)], p('en-AU;q=0.123')) self.assertEqual([('en-au', 0.5)], p('en-au;q=0.5')) @@ -739,6 +740,7 @@ class MiscTests(TestCase): self.assertEqual([], p('da, en-gb;q=0.8, en;q=0.7,#')) self.assertEqual([], p('de;q=2.0')) self.assertEqual([], p('de;q=0.a')) + self.assertEqual([], p('12-345')) self.assertEqual([], p('')) def test_parse_literal_http_header(self):