Fixed #19488 -- Made i18n_patterns redirect work with non-slash-ending paths
Thanks Daniel Gerzo for the report and the initial patch.
This commit is contained in:
parent
f08e739bc2
commit
bcdb4898ca
|
@ -31,10 +31,12 @@ class LocaleMiddleware(object):
|
||||||
and self.is_language_prefix_patterns_used()):
|
and self.is_language_prefix_patterns_used()):
|
||||||
urlconf = getattr(request, 'urlconf', None)
|
urlconf = getattr(request, 'urlconf', None)
|
||||||
language_path = '/%s%s' % (language, request.path_info)
|
language_path = '/%s%s' % (language, request.path_info)
|
||||||
if settings.APPEND_SLASH and not language_path.endswith('/'):
|
path_valid = is_valid_path(language_path, urlconf)
|
||||||
language_path = language_path + '/'
|
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" % (
|
language_url = "%s://%s/%s%s" % (
|
||||||
request.is_secure() and 'https' or 'http',
|
request.is_secure() and 'https' or 'http',
|
||||||
request.get_host(), language, request.get_full_path())
|
request.get_host(), language, request.get_full_path())
|
||||||
|
|
|
@ -115,6 +115,7 @@ class URLTranslationTests(URLTestCaseBase):
|
||||||
|
|
||||||
with translation.override('nl'):
|
with translation.override('nl'):
|
||||||
self.assertEqual(reverse('users'), '/nl/gebruikers/')
|
self.assertEqual(reverse('users'), '/nl/gebruikers/')
|
||||||
|
self.assertEqual(reverse('prefixed_xml'), '/nl/prefixed.xml')
|
||||||
|
|
||||||
with translation.override('pt-br'):
|
with translation.override('pt-br'):
|
||||||
self.assertEqual(reverse('users'), '/pt-br/usuarios/')
|
self.assertEqual(reverse('users'), '/pt-br/usuarios/')
|
||||||
|
@ -186,6 +187,9 @@ class URLRedirectWithoutTrailingSlashTests(URLTestCaseBase):
|
||||||
self.assertIn(('http://testserver/en/account/register/', 301), response.redirect_chain)
|
self.assertIn(('http://testserver/en/account/register/', 301), response.redirect_chain)
|
||||||
self.assertRedirects(response, '/en/account/register/', 302)
|
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):
|
class URLRedirectWithoutTrailingSlashSettingTests(URLTestCaseBase):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -14,6 +14,7 @@ urlpatterns = patterns('',
|
||||||
|
|
||||||
urlpatterns += i18n_patterns('',
|
urlpatterns += i18n_patterns('',
|
||||||
url(r'^prefixed/$', view, name='prefixed'),
|
url(r'^prefixed/$', view, name='prefixed'),
|
||||||
|
url(r'^prefixed\.xml$', view, name='prefixed_xml'),
|
||||||
url(_(r'^users/$'), view, name='users'),
|
url(_(r'^users/$'), view, name='users'),
|
||||||
url(_(r'^account/'), include('regressiontests.i18n.patterns.urls.namespace', namespace='account')),
|
url(_(r'^account/'), include('regressiontests.i18n.patterns.urls.namespace', namespace='account')),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue