Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@claudep claudep authored
View
8 django/middleware/locale.py
@@ -31,10 +31,12 @@ def process_response(self, request, response):
and self.is_language_prefix_patterns_used()):
urlconf = getattr(request, 'urlconf', None)
language_path = '/%s%s' % (language, request.path_info)
- if settings.APPEND_SLASH and not language_path.endswith('/'):
- language_path = language_path + '/'
+ path_valid = is_valid_path(language_path, urlconf)
+ if (not path_valid and settings.APPEND_SLASH
+ and not language_path.endswith('/')):
+ path_valid = is_valid_path("%s/" % language_path, urlconf)
- if is_valid_path(language_path, urlconf):
+ if path_valid:
language_url = "%s://%s/%s%s" % (
request.is_secure() and 'https' or 'http',
request.get_host(), language, request.get_full_path())
View
4 tests/regressiontests/i18n/patterns/tests.py
@@ -115,6 +115,7 @@ def test_users_url(self):
with translation.override('nl'):
self.assertEqual(reverse('users'), '/nl/gebruikers/')
+ self.assertEqual(reverse('prefixed_xml'), '/nl/prefixed.xml')
with translation.override('pt-br'):
self.assertEqual(reverse('users'), '/pt-br/usuarios/')
@@ -186,6 +187,9 @@ def test_en_redirect(self):
self.assertIn(('http://testserver/en/account/register/', 301), response.redirect_chain)
self.assertRedirects(response, '/en/account/register/', 302)
+ response = self.client.get('/prefixed.xml', HTTP_ACCEPT_LANGUAGE='en', follow=True)
+ self.assertRedirects(response, '/en/prefixed.xml', 302)
+
class URLRedirectWithoutTrailingSlashSettingTests(URLTestCaseBase):
"""
View
1  tests/regressiontests/i18n/patterns/urls/default.py
@@ -14,6 +14,7 @@
urlpatterns += i18n_patterns('',
url(r'^prefixed/$', view, name='prefixed'),
+ url(r'^prefixed\.xml$', view, name='prefixed_xml'),
url(_(r'^users/$'), view, name='users'),
url(_(r'^account/'), include('regressiontests.i18n.patterns.urls.namespace', namespace='account')),
)

0 comments on commit bcdb489

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