From f46a838efc9482c9c7834a83a152b57a56888fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20Engstr=C3=B6m?= Date: Sun, 6 Nov 2016 10:38:36 +0100 Subject: [PATCH] Fixed #26812 -- Fixed APPEND_SLASH on a URL including querystring with a trailing slash. --- django/middleware/common.py | 2 +- tests/middleware/tests.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/django/middleware/common.py b/django/middleware/common.py index 820609e3a5..d18d23fa43 100644 --- a/django/middleware/common.py +++ b/django/middleware/common.py @@ -74,7 +74,7 @@ class CommonMiddleware(MiddlewareMixin): Return True if settings.APPEND_SLASH is True and appending a slash to the request path turns an invalid path into a valid one. """ - if settings.APPEND_SLASH and not request.get_full_path().endswith('/'): + if settings.APPEND_SLASH and not request.path_info.endswith('/'): urlconf = getattr(request, 'urlconf', None) return ( not is_valid_path(request.path_info, urlconf) and diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py index a51c4eeb31..7f8faf7630 100644 --- a/tests/middleware/tests.py +++ b/tests/middleware/tests.py @@ -83,6 +83,18 @@ class CommonMiddlewareTest(SimpleTestCase): r = CommonMiddleware().process_response(request, response) self.assertEqual(r.url, '/slash/?test=1') + @override_settings(APPEND_SLASH=True) + def test_append_slash_redirect_querystring_have_slash(self): + """ + APPEND_SLASH should append slash to path when redirecting a request + with a querystring ending with slash. + """ + request = self.rf.get('/slash?test=slash/') + response = HttpResponseNotFound() + r = CommonMiddleware().process_response(request, response) + self.assertIsInstance(r, HttpResponsePermanentRedirect) + self.assertEqual(r.url, '/slash/?test=slash/') + @override_settings(APPEND_SLASH=True, DEBUG=True) def test_append_slash_no_redirect_on_POST_in_DEBUG(self): """