mirror of
https://github.com/django/django.git
synced 2025-01-26 02:00:08 +00:00
Fixed #34742 -- Made CommonMiddleware raise APPEND_SLASH RuntimeError on DELETE requests.
This commit is contained in:
parent
5b3b791e90
commit
705b1702bd
@ -78,12 +78,12 @@ class CommonMiddleware(MiddlewareMixin):
|
|||||||
Return the full path of the request with a trailing slash appended.
|
Return the full path of the request with a trailing slash appended.
|
||||||
|
|
||||||
Raise a RuntimeError if settings.DEBUG is True and request.method is
|
Raise a RuntimeError if settings.DEBUG is True and request.method is
|
||||||
POST, PUT, or PATCH.
|
DELETE, POST, PUT, or PATCH.
|
||||||
"""
|
"""
|
||||||
new_path = request.get_full_path(force_append_slash=True)
|
new_path = request.get_full_path(force_append_slash=True)
|
||||||
# Prevent construction of scheme relative urls.
|
# Prevent construction of scheme relative urls.
|
||||||
new_path = escape_leading_slashes(new_path)
|
new_path = escape_leading_slashes(new_path)
|
||||||
if settings.DEBUG and request.method in ("POST", "PUT", "PATCH"):
|
if settings.DEBUG and request.method in ("DELETE", "POST", "PUT", "PATCH"):
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"You called this URL via %(method)s, but the URL doesn't end "
|
"You called this URL via %(method)s, but the URL doesn't end "
|
||||||
"in a slash and you have APPEND_SLASH set. Django can't "
|
"in a slash and you have APPEND_SLASH set. Django can't "
|
||||||
|
@ -107,11 +107,11 @@ class CommonMiddlewareTest(SimpleTestCase):
|
|||||||
self.assertEqual(resp.url, "/slash/?test=slash/")
|
self.assertEqual(resp.url, "/slash/?test=slash/")
|
||||||
|
|
||||||
@override_settings(APPEND_SLASH=True, DEBUG=True)
|
@override_settings(APPEND_SLASH=True, DEBUG=True)
|
||||||
def test_append_slash_no_redirect_on_POST_in_DEBUG(self):
|
def test_append_slash_no_redirect_in_DEBUG(self):
|
||||||
"""
|
"""
|
||||||
While in debug mode, an exception is raised with a warning
|
While in debug mode, an exception is raised with a warning
|
||||||
when a failed attempt is made to POST, PUT, or PATCH to an URL which
|
when a failed attempt is made to DELETE, POST, PUT, or PATCH to an URL
|
||||||
would normally be redirected to a slashed version.
|
which would normally be redirected to a slashed version.
|
||||||
"""
|
"""
|
||||||
msg = "maintaining %s data. Change your form to point to testserver/slash/"
|
msg = "maintaining %s data. Change your form to point to testserver/slash/"
|
||||||
request = self.rf.get("/slash")
|
request = self.rf.get("/slash")
|
||||||
@ -126,6 +126,9 @@ class CommonMiddlewareTest(SimpleTestCase):
|
|||||||
request.method = "PATCH"
|
request.method = "PATCH"
|
||||||
with self.assertRaisesMessage(RuntimeError, msg % request.method):
|
with self.assertRaisesMessage(RuntimeError, msg % request.method):
|
||||||
CommonMiddleware(get_response_404)(request)
|
CommonMiddleware(get_response_404)(request)
|
||||||
|
request = self.rf.delete("/slash")
|
||||||
|
with self.assertRaisesMessage(RuntimeError, msg % request.method):
|
||||||
|
CommonMiddleware(get_response_404)(request)
|
||||||
|
|
||||||
@override_settings(APPEND_SLASH=False)
|
@override_settings(APPEND_SLASH=False)
|
||||||
def test_append_slash_disabled(self):
|
def test_append_slash_disabled(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user