зеркало из https://github.com/mozilla/bedrock.git
Fix #11890: Append slash at locale root URL
This commit is contained in:
Родитель
b59ff15fb0
Коммит
89ed50238a
|
@ -166,7 +166,10 @@ def render(request, template, context=None, ftl_files=None, activation_files=Non
|
|||
|
||||
# Does that path's locale match the request's locale?
|
||||
if locale in translations:
|
||||
if locale != request.path.lstrip("/").partition("/")[0]:
|
||||
# Redirect to the locale if:
|
||||
# - The URL is the root path but is missing the trailing slash OR
|
||||
# - The locale isn't in current prefix in the URL.
|
||||
if request.path == f"/{locale}" or locale != request.path.lstrip("/").partition("/")[0]:
|
||||
return redirect_to_locale(request, locale)
|
||||
else:
|
||||
return redirect_to_best_locale(request, translations)
|
||||
|
|
|
@ -62,6 +62,8 @@ class TestRender(TestCase):
|
|||
self._test("/firefox/new/", template, "", "", 404, active_locales=locales)
|
||||
|
||||
# Test that a locale+path and no accept language header returns 200 as long as the locales are supported.
|
||||
self._test("/en-US", template, "", "", 302, "/en-US/", active_locales=locales)
|
||||
self._test("/en-US/", template, "", "", 200, active_locales=locales)
|
||||
self._test("/en-US/firefox/new/", template, "", "", 200, active_locales=locales)
|
||||
self._test("/en-GB/firefox/new/", template, "", "", 200, active_locales=locales)
|
||||
self._test("/fr/firefox/new/", template, "", "", 200, active_locales=locales)
|
||||
|
|
Загрузка…
Ссылка в новой задаче