Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#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: danger@… 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)

t19488.tar.gz (6.2 KB ) - added by danger@… 11 years ago.
sample project
t19488.tar.2.gz (5.9 KB ) - added by danger@… 11 years ago.
cleanup a bit.
19488-1.diff (2.7 KB ) - added by Claude Paroz 11 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 by Aymeric Augustin, 11 years ago

Could you paste your MIDDLEWARE_CLASSES setting?

comment:2 by danger@…, 11 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 Russell Keith-Magee, 11 years ago

Resolution: worksforme
Status: newclosed

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.

by danger@…, 11 years ago

Attachment: t19488.tar.gz added

sample project

comment:4 by danger@…, 11 years ago

Resolution: worksforme
Status: closednew

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/

by danger@…, 11 years ago

Attachment: t19488.tar.2.gz added

cleanup a bit.

comment:5 by danger@…, 11 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 Claude Paroz, 11 years ago

Attachment: 19488-1.diff added

comment:6 by Claude Paroz, 11 years ago

Triage Stage: UnreviewedAccepted

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 Claude Paroz <claude@…>, 11 years ago

Resolution: fixed
Status: newclosed

In bcdb4898cae2f24599b39845b8e4cd7edc202424:

Fixed #19488 -- Made i18n_patterns redirect work with non-slash-ending paths

Thanks Daniel Gerzo for the report and the initial patch.

comment:8 by Claude Paroz <claude@…>, 11 years ago

In b3887ab98ac5317ebe7889e8b35752ebfd9740f9:

[1.5.x] Fixed #19488 -- Made i18n_patterns redirect work with non-slash-ending paths

Thanks Daniel Gerzo for the report and the initial patch.
Backport of bcdb4898c from master.

comment:9 by anonymous, 11 years ago

thanks!

comment:10 by Claude Paroz <claude@…>, 11 years ago

In b3887ab98ac5317ebe7889e8b35752ebfd9740f9:

[1.5.x] Fixed #19488 -- Made i18n_patterns redirect work with non-slash-ending paths

Thanks Daniel Gerzo for the report and the initial patch.
Backport of bcdb4898c from master.

Note: See TracTickets for help on using tickets.
Back to Top