diff --git a/django/middleware/locale.py b/django/middleware/locale.py index 628782b1815..f693e4d242a 100644 --- a/django/middleware/locale.py +++ b/django/middleware/locale.py @@ -31,10 +31,12 @@ class LocaleMiddleware(object): 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()) diff --git a/tests/regressiontests/i18n/patterns/tests.py b/tests/regressiontests/i18n/patterns/tests.py index 358cdf65db8..639e03f2887 100644 --- a/tests/regressiontests/i18n/patterns/tests.py +++ b/tests/regressiontests/i18n/patterns/tests.py @@ -115,6 +115,7 @@ class URLTranslationTests(URLTestCaseBase): 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 @@ class URLRedirectWithoutTrailingSlashTests(URLTestCaseBase): 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): """ diff --git a/tests/regressiontests/i18n/patterns/urls/default.py b/tests/regressiontests/i18n/patterns/urls/default.py index f1175027530..00b90b14b7a 100644 --- a/tests/regressiontests/i18n/patterns/urls/default.py +++ b/tests/regressiontests/i18n/patterns/urls/default.py @@ -14,6 +14,7 @@ urlpatterns = patterns('', 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')), )