1
0
mirror of https://github.com/django/django.git synced 2025-01-12 03:15:47 +00:00

Fixed -- Made CommonMiddleware raise APPEND_SLASH RuntimeError on DELETE requests.

This commit is contained in:
Avaneesh Kumar 2023-12-07 02:54:52 -06:00 committed by Mariusz Felisiak
parent 5b3b791e90
commit 705b1702bd
2 changed files with 8 additions and 5 deletions
django/middleware
tests/middleware

View File

@ -78,12 +78,12 @@ class CommonMiddleware(MiddlewareMixin):
Return the full path of the request with a trailing slash appended.
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)
# Prevent construction of scheme relative urls.
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(
"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 "

View File

@ -107,11 +107,11 @@ class CommonMiddlewareTest(SimpleTestCase):
self.assertEqual(resp.url, "/slash/?test=slash/")
@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
when a failed attempt is made to POST, PUT, or PATCH to an URL which
would normally be redirected to a slashed version.
when a failed attempt is made to DELETE, POST, PUT, or PATCH to an URL
which would normally be redirected to a slashed version.
"""
msg = "maintaining %s data. Change your form to point to testserver/slash/"
request = self.rf.get("/slash")
@ -126,6 +126,9 @@ class CommonMiddlewareTest(SimpleTestCase):
request.method = "PATCH"
with self.assertRaisesMessage(RuntimeError, msg % request.method):
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)
def test_append_slash_disabled(self):