Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17555 -- Added support for a missing trailing slash when redir…

…ecting based on the browser language. Thanks, neaf.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17443 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ef4d84d11ab9357d9c6e35b2a3a0a9d4fb310075 1 parent 878cc62
Jannis Leidel authored February 04, 2012
2  django/utils/translation/trans_real.py
@@ -38,7 +38,7 @@
38 38
         (?:\s*,\s*|$)                                 # Multiple accepts per header.
39 39
         ''', re.VERBOSE)
40 40
 
41  
-language_code_prefix_re = re.compile(r'^/([\w-]+)/')
  41
+language_code_prefix_re = re.compile(r'^/([\w-]+)(/|$)')
42 42
 
43 43
 def to_locale(language, to_lower=False):
44 44
     """
12  tests/regressiontests/i18n/tests.py
@@ -793,6 +793,18 @@ def test_parse_language_cookie(self):
793 793
         r.META = {'HTTP_ACCEPT_LANGUAGE': 'de'}
794 794
         self.assertEqual(g(r), 'zh-cn')
795 795
 
  796
+    def test_get_language_from_path(self):
  797
+        from django.utils.translation.trans_real import get_language_from_path as g
  798
+        self.assertEqual(g('/pl/'), 'pl')
  799
+        self.assertEqual(g('/pl'), 'pl')
  800
+        self.assertEqual(g('/xyz/'), None)
  801
+
  802
+    def test_get_language_from_path(self):
  803
+        from django.utils.translation.trans_null import get_language_from_path as g
  804
+        self.assertEqual(g('/pl/'), None)
  805
+        self.assertEqual(g('/pl'), None)
  806
+        self.assertEqual(g('/xyz/'), None)
  807
+
796 808
     def test_percent_in_translatable_block(self):
797 809
         extended_locale_paths = settings.LOCALE_PATHS + (
798 810
             os.path.join(here, 'other', 'locale'),

0 notes on commit ef4d84d

Please sign in to comment.
Something went wrong with that request. Please try again.