Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #19488 -- Made i18n_patterns redirect work with non-slash-endin…

…g paths

Thanks Daniel Gerzo for the report and the initial patch.
  • Loading branch information...
commit bcdb4898cae2f24599b39845b8e4cd7edc202424 1 parent f08e739
Claude Paroz authored January 11, 2013
8  django/middleware/locale.py
@@ -31,10 +31,12 @@ def process_response(self, request, response):
31 31
                     and self.is_language_prefix_patterns_used()):
32 32
             urlconf = getattr(request, 'urlconf', None)
33 33
             language_path = '/%s%s' % (language, request.path_info)
34  
-            if settings.APPEND_SLASH and not language_path.endswith('/'):
35  
-                language_path = language_path + '/'
  34
+            path_valid = is_valid_path(language_path, urlconf)
  35
+            if (not path_valid and settings.APPEND_SLASH
  36
+                    and not language_path.endswith('/')):
  37
+                path_valid = is_valid_path("%s/" % language_path, urlconf)
36 38
 
37  
-            if is_valid_path(language_path, urlconf):
  39
+            if path_valid:
38 40
                 language_url = "%s://%s/%s%s" % (
39 41
                     request.is_secure() and 'https' or 'http',
40 42
                     request.get_host(), language, request.get_full_path())
4  tests/regressiontests/i18n/patterns/tests.py
@@ -115,6 +115,7 @@ def test_users_url(self):
115 115
 
116 116
         with translation.override('nl'):
117 117
             self.assertEqual(reverse('users'), '/nl/gebruikers/')
  118
+            self.assertEqual(reverse('prefixed_xml'), '/nl/prefixed.xml')
118 119
 
119 120
         with translation.override('pt-br'):
120 121
             self.assertEqual(reverse('users'), '/pt-br/usuarios/')
@@ -186,6 +187,9 @@ def test_en_redirect(self):
186 187
         self.assertIn(('http://testserver/en/account/register/', 301), response.redirect_chain)
187 188
         self.assertRedirects(response, '/en/account/register/', 302)
188 189
 
  190
+        response = self.client.get('/prefixed.xml', HTTP_ACCEPT_LANGUAGE='en', follow=True)
  191
+        self.assertRedirects(response, '/en/prefixed.xml', 302)
  192
+
189 193
 
190 194
 class URLRedirectWithoutTrailingSlashSettingTests(URLTestCaseBase):
191 195
     """
1  tests/regressiontests/i18n/patterns/urls/default.py
@@ -14,6 +14,7 @@
14 14
 
15 15
 urlpatterns += i18n_patterns('',
16 16
     url(r'^prefixed/$', view, name='prefixed'),
  17
+    url(r'^prefixed\.xml$', view, name='prefixed_xml'),
17 18
     url(_(r'^users/$'), view, name='users'),
18 19
     url(_(r'^account/'), include('regressiontests.i18n.patterns.urls.namespace', namespace='account')),
19 20
 )

0 notes on commit bcdb489

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