Code

Opened 13 months ago

Closed 13 months ago

Last modified 13 months ago

#20169 closed Bug (fixed)

Request path incorrectly assembled when SCRIPT_NAME has trailing slash

Reported by: julien Owned by: nobody
Component: HTTP handling Version: 1.5
Severity: Normal Keywords:
Cc: bmispelon@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If the request's SCRIPT_NAME, or the FORCE_SCRIPT_NAME setting, has a trailing slash, then the path is incorrectly assembled and contains one too many slash. See for example:

>>> from io import BytesIO
>>> from django.core.handlers.wsgi import WSGIRequest
>>> request = WSGIRequest({'PATH_INFO': '/somepath/', 'SCRIPT_NAME': '/PREFIX/', 'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')})
>>> request.path
u'/PREFIX//somepath/'

The attached pull request should fix this in a backwards-compatible way.

Attachments (0)

Change History (5)

comment:1 Changed 13 months ago by julien

Here's the pull request: https://github.com/django/django/pull/980

The added benefit of that patch is that it adds tests for the FORCE_SCRIPT_NAME which didn't seem to be tested at all before.

comment:2 Changed 13 months ago by bmispelon

  • Cc bmispelon@… added
  • Triage Stage changed from Unreviewed to Accepted

The patch looks good but there's a typo in the test's docstrings: s/regarless/regardless/ (2 occurences).

Also, as you noted, there's currently no tests for the FORCE_SCRIPT_NAME feature. Maybe this would be a good occation to add one (checking that FORCE_SCRIPT_NAME does indeed overwrite the request's SCRIPT_NAME).

comment:3 Changed 13 months ago by julien

Thanks for the suggestion. I've added a test to the PR and will be pushing this shortly.

comment:4 Changed 13 months ago by Julien Phalip <jphalip@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 2f81a0ca6543f4f7b59bf6cd9aeb8ae87f1e968e:

Fixed #20169 -- Ensured that the WSGI request's path is correctly based on the SCRIPT_NAME environment parameter or the FORCE_SCRIPT_NAME setting, regardless of whether or not those have a trailing slash. Thanks to bmispelon for the review.

comment:5 Changed 13 months ago by Julien Phalip <jphalip@…>

In a15a3e9148e9707f8ab3477be512546e7cf73607:

[1.5.x] Fixed #20169 -- Ensured that the WSGI request's path is correctly based on the SCRIPT_NAME environment parameter or the FORCE_SCRIPT_NAME setting, regardless of whether or not those have a trailing slash. Thanks to bmispelon for the review.
Backport of 2f81a0ca6543f

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.