#19488 closed Bug (fixed)
Locale middleware with settings.APPEND_SLASH enabled is buggy (doesn't redirect) with valid URLs not ending with slash
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Other) | Version: | 1.4 |
Severity: | Normal | Keywords: | redirect, i18n, locale middleware |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hello,
the locale middleware does not handle the case when settings.APPEND_SLASH is enabled and a valid URL that doesn't end with slash is accessed. Example:
i18n url pattern ^sitemap\.xml$
I access domain.tld/sitemap.xml
The middleware checks if settings.APPEND_SLASH and not language_path.endswith('/') and in that case appends '/' to the url, so we get something like language_path=u'/en/sitemap.xml/'.
That in turn does not match any of the urls because our regexp doesn't allow slash at the end for sitemap.xml and we get 404 instead of redirect to /en/sitemap.xml.
My pull request is at https://github.com/django/django/pull/591
Attachments (3)
Change History (13)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Pretty standard:
MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.locale.LocaleMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', )
comment:3 by , 12 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
I haven't been able to reproduce this problem - an i18n URL pattern, ending in \.xml$ with APPEND_SLASH=True doesn't redirect for me. Feel free to reopen if you can provide a minimal test project that demonstrates the problem.
comment:4 by , 12 years ago
Resolution: | worksforme |
---|---|
Status: | closed → new |
I have attached a sample project which demonstrates my problem.
When you try accessing /index.html I belive it should redirect to /en/index.html the same way as it does when you access /ok and you get redirected to /en/ok/
comment:5 by , 12 years ago
additional note: when you define the url pattern straight in the top-level urls.py file (in i18n_patterns), the redirect works fine. The problem seems to start when you go through the include() statement.
by , 12 years ago
Attachment: | 19488-1.diff added |
---|
comment:6 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
I think I reproduced (and fixed) the issue in the attached patch. Compared to the pull request, I re-arranged some lines so as is_valid_path
is not called twice if not necessary.
comment:7 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Could you paste your MIDDLEWARE_CLASSES setting?