[Django] #32790: Django test client redirecting to URLs without a trailing slash redirects instead to the current view

24 views
Skip to first unread message

Django

unread,
May 27, 2021, 5:51:41 AM5/27/21
to django-...@googlegroups.com
#32790: Django test client redirecting to URLs without a trailing slash redirects
instead to the current view
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
tomhamiltonstubber |
Type: Bug | Status: new
Component: Testing | Version: 3.2
framework |
Severity: Normal | Keywords: Test client
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Currently, when you redirect with the test client to an external URL
without a trailing slash, the test client will redirect to the view you
redirected from.

For example, if I test a view at `/my-view/` that redirects to
`https://example.com`, the test client will instead redirect to `/my-
view/`.

Presumably this isn't intended behaviour but feel free to correct me.

--
Ticket URL: <https://code.djangoproject.com/ticket/32790>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 27, 2021, 5:53:03 AM5/27/21
to django-...@googlegroups.com
#32790: Django test client redirecting to URLs without a trailing slash redirects
instead to the current view
-------------------------------------+-------------------------------------
Reporter: tomhamiltonstubber | Owner:
| tomhamiltonstubber
Type: Bug | Status: assigned
Component: Testing framework | Version: 3.2
Severity: Normal | Resolution:

Keywords: Test client | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by tomhamiltonstubber):

* owner: nobody => tomhamiltonstubber
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/32790#comment:1>

Django

unread,
May 27, 2021, 5:57:43 AM5/27/21
to django-...@googlegroups.com
#32790: Django test client redirecting to URLs without a trailing slash redirects
instead to the current view
-------------------------------------+-------------------------------------
Reporter: tomhamiltonstubber | Owner:
| tomhamiltonstubber
Type: Bug | Status: assigned
Component: Testing framework | Version: 3.2
Severity: Normal | Resolution:
Keywords: Test client | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by tomhamiltonstubber):

PR https://github.com/django/django/pull/14457

--
Ticket URL: <https://code.djangoproject.com/ticket/32790#comment:2>

Django

unread,
May 27, 2021, 6:10:54 AM5/27/21
to django-...@googlegroups.com
#32790: Django test client redirecting to URLs without a trailing slash redirects
instead to the current view
-------------------------------------+-------------------------------------
Reporter: tomhamiltonstubber | Owner:
| tomhamiltonstubber
Type: Bug | Status: assigned
Component: Testing framework | Version: 3.2
Severity: Normal | Resolution:
Keywords: Test client | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by tomhamiltonstubber):

* stage: Unreviewed => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32790#comment:3>

Django

unread,
May 27, 2021, 7:04:13 AM5/27/21
to django-...@googlegroups.com
#32790: Django test client redirecting to URLs without a trailing slash redirects
instead to the current view
-------------------------------------+-------------------------------------
Reporter: Tom Hamilton | Owner: Tom
Stubber | Hamilton Stubber

Type: Bug | Status: assigned
Component: Testing framework | Version: 3.2
Severity: Normal | Resolution:
Keywords: Test client | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Ready for checkin => Unreviewed


Comment:

You shouldn't accept or mark as RFC your own tickets/PRs.

--
Ticket URL: <https://code.djangoproject.com/ticket/32790#comment:4>

Django

unread,
Jun 1, 2021, 3:29:07 AM6/1/21
to django-...@googlegroups.com
#32790: Django test client redirecting to URLs without a trailing slash redirects
instead to the current view
-------------------------------------+-------------------------------------
Reporter: Tom Hamilton | Owner: Tom
Stubber | Hamilton Stubber
Type: Bug | Status: assigned
Component: Testing framework | Version: 3.2
Severity: Normal | Resolution:
Keywords: Test client | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Unreviewed => Accepted


Comment:

I think this is probably valid. I su

[https://datatracker.ietf.org/doc/html/rfc2616#section-3.2.2 RFC 2616
(HTTP/1.1) has this for an HTTP URL]:

{{{
http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]
}}}

It then says:

> If the abs_path is not present in the URL, it MUST be given as "/" when
used as a Request-URI for a resource.

i.e. the client MUST treat `https://example.com` as
`https://example.com/`.

(Inclined towards thinking this should probably apply to the `Location`
headers **set by the server** too, but the test client can't control for
that.)

--
Ticket URL: <https://code.djangoproject.com/ticket/32790#comment:5>

Django

unread,
Jun 23, 2021, 6:39:48 AM6/23/21
to django-...@googlegroups.com
#32790: Django test client redirecting to URLs without a trailing slash redirects
instead to the current view
-------------------------------------+-------------------------------------
Reporter: Tom Hamilton | Owner: Tom
Stubber | Hamilton Stubber
Type: Bug | Status: assigned
Component: Testing framework | Version: 3.2
Severity: Normal | Resolution:
Keywords: Test client | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32790#comment:6>

Django

unread,
Jun 23, 2021, 8:53:33 AM6/23/21
to django-...@googlegroups.com
#32790: Django test client redirecting to URLs without a trailing slash redirects
instead to the current view
-------------------------------------+-------------------------------------
Reporter: Tom Hamilton | Owner: Tom
Stubber | Hamilton Stubber
Type: Bug | Status: closed

Component: Testing framework | Version: 3.2
Severity: Normal | Resolution: fixed

Keywords: Test client | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton.gibson@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"1e5aa8e1c79252cc810af21294a6e945d11d37b3" 1e5aa8e1]:
{{{
#!CommitTicketReference repository=""
revision="1e5aa8e1c79252cc810af21294a6e945d11d37b3"
Fixed #32790 -- Ensured test Client handles redirects to domain indexes
without a specified trailing slash.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32790#comment:7>

Reply all
Reply to author
Forward
0 new messages