Skip to content

Commit

Permalink
Add test for redirects without trailing slash being redirected in one go
Browse files Browse the repository at this point in the history
  • Loading branch information
gasman committed Mar 25, 2024
1 parent 450187a commit e58b0e0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions wagtail/contrib/redirects/tests/test_redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ def test_temporary_redirect(self):
response, "/redirectto", status_code=302, fetch_redirect_response=False
)

def test_redirect_without_trailing_slash(self):
# Create a redirect
redirect = models.Redirect(old_path="/redirectme", redirect_link="/redirectto")
redirect.save()

response = self.client.get("/redirectme")
# Request should be picked up by RedirectMiddleware, not CommonMiddleware
# (which would redirect to /redirectme/ instead).
# Before Django 4.2, CommonMiddleware performed the 'add trailing slash' test
# during the initial request processing, which took precedence over RedirectMiddleware
# and caused a double redirect (/redirectme -> /redirectme/ -> /redirectto).
self.assertRedirects(
response, "/redirectto", status_code=301, fetch_redirect_response=False
)

def test_redirect_stripping_query_string(self):
# Create a redirect which includes a query string
redirect_with_query_string = models.Redirect(
Expand Down

0 comments on commit e58b0e0

Please sign in to comment.