Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#20169 closed Bug (fixed)

Request path incorrectly assembled when SCRIPT_NAME has trailing slash

Reported by: Julien Phalip 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.

Change History (5)

comment:1 by Julien Phalip, 11 years ago

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 by Baptiste Mispelon, 11 years ago

Cc: bmispelon@… added
Triage Stage: UnreviewedAccepted

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 by Julien Phalip, 11 years ago

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

comment:4 by Julien Phalip <jphalip@…>, 11 years ago

Resolution: fixed
Status: newclosed

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 by Julien Phalip <jphalip@…>, 11 years ago

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

Note: See TracTickets for help on using tickets.
Back to Top