[Django] #18314: request.build_absolute_uri() functions incorrectly when the path starts with //

90 views
Skip to first unread message

Django

unread,
May 14, 2012, 2:25:06 PM5/14/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+--------------------
Reporter: anonymous | Owner: nobody
Type: Uncategorized | Status: new
Component: HTTP handling | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------
A request to:

http://www.example.com:8080//django-ate-my-baby/

leads to request.build_absolute_uri() returning:

http://django-ate-my-baby/

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

Django

unread,
May 15, 2012, 2:57:12 AM5/15/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: nobody
Type: Bug | Status: new
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by claudep):

* needs_docs: => 0
* needs_better_patch: => 0
* type: Uncategorized => Bug
* needs_tests: => 1
* stage: Unreviewed => Accepted


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

Django

unread,
May 15, 2012, 1:33:56 PM5/15/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: yoyoma
Type: Bug | Status: new
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by yoyoma):

* owner: nobody => yoyoma


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

Django

unread,
May 15, 2012, 3:30:08 PM5/15/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: yoyoma
Type: Bug | Status: closed
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by yoyoma):

* status: new => closed
* has_patch: 0 => 1
* resolution: => fixed


Comment:

I've attached the fix, but if it needs improvements, let me know and I'll
update the diff ASAP.

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

Django

unread,
May 15, 2012, 4:05:56 PM5/15/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: yoyoma
Type: Bug | Status: reopened
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by yoyoma):

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


Comment:

Pardon my resolving of the ticket.

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

Django

unread,
May 15, 2012, 4:30:29 PM5/15/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: yoyoma
Type: Bug | Status: reopened
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by yoyoma):

* needs_tests: 1 => 0


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

Django

unread,
May 19, 2012, 2:43:59 PM5/19/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: yoyoma
Type: Bug | Status: reopened
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by abhaga):

* cc: abhaga (added)
* needs_better_patch: 0 => 1


Comment:

Since the original function as well as your patch is using {{{self.path}}}
to construct the {{{base_uri}}}, query parameters are not preserved
anyway. So branching doesn't serve any purpose.
One simpler way is to strip out the additional slashes in the beginning of
{{{self.path}}} in this function. It may be better to do that where the
request is initialized.

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

Django

unread,
May 19, 2012, 3:17:28 PM5/19/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: yoyoma
Type: Bug | Status: reopened
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by abhaga):

Also str.format was introduced in Python 2.6 while Django 1.4 supports
Python 2.5 also. So that should be reverted back to old style string
interpolation.

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

Django

unread,
May 21, 2012, 9:43:36 AM5/21/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: yoyoma
Type: Bug | Status: reopened
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by yoyoma):

Replying to [comment:6 abhaga]:

> Since the original function as well as your patch is using
{{{self.path}}} to construct the {{{base_uri}}}, query parameters are not
preserved anyway. So branching doesn't serve any purpose.
> One simpler way is to strip out the additional slashes in the beginning
of {{{self.path}}} in this function. It may be better to do that where the
request is initialized.

That is incorrect. {{{location}}}, if provided or not is joined with the
{{{base_uri}}}, and when not provided is built using
[https://docs.djangoproject.com/en/dev/ref/request-
response/#django.http.HttpRequest.get_full_path request.get_full_path()].
This happens in both my patch and the original.

{{{
>>> from urlparse import urljoin
>>> urljoin('http://www.example.com/foo/',
'http://www.example.com/foo/?bar=baz')
'http://www.example.com/foo/?bar=baz'
}}}

Regarding the usage of {{{basestring.format()}}}, I'll provide an updated
patch which uses string interpolation.

--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:8>

Django

unread,
May 25, 2012, 1:02:48 AM5/25/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: yoyoma
Type: Bug | Status: reopened
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by SmileyChris):

* needs_better_patch: 1 => 0


Comment:

Here's a simpler way to do it.

--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:9>

Django

unread,
May 25, 2012, 2:39:33 PM5/25/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: yoyoma
Type: Bug | Status: reopened
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by yoyoma):

Replying to [comment:9 SmileyChris]:

> Here's a simpler way to do it.

I don't mean to sound too competitive, but I think my patch is as simple
as possible, but no simpler :P It only has 2 very simple logical branches,
and requires no hacking. I think prepending {{{'//'}}} to
{{{self.get_full_path()}}} is a bit hacky, as it simply takes advantage
{{{urlsplit}}} setting {{{netloc}}} to {{{''}}} when a URL starts with
{{{//}}} (explicit over implicit comes to mind here).

Also worth noting is:

{{{
if not location:
}}}

Not using {{{is not None}}} here could lead to an unintended result, if
ever a bug were to cause this method to be called with an empty string
provided as the {{{location}}} argument.

--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:10>

Django

unread,
Aug 6, 2012, 1:06:54 PM8/6/12
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: yoyoma
Type: Bug | Status: reopened
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by anonymous):

Any word on which patch will go to master? Both include passing tests for
regression, etc., and both provide the exact same result.

--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:11>

Django

unread,
Jun 9, 2013, 9:22:34 AM6/9/13
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: yoyoma
Type: Bug | Status: new

Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Kamu):

* needs_better_patch: 0 => 1


Comment:

If I am not mistaken the patch requires updating. The test files being
patched no longer exist at that location.

--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:13>

Django

unread,
Jun 25, 2013, 3:48:53 AM6/25/13
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: susan
Type: Bug | Status: assigned

Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by susan):

* owner: yoyoma => susan
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:14>

Django

unread,
Jun 29, 2013, 2:26:23 AM6/29/13
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: susan
Type: Bug | Status: assigned
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by susan):

The 1st test fails.But the other 3 pass. Can someone also test this patch?
Hmm. Well, I'm going to have to fix up the patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:15>

Django

unread,
Jun 29, 2013, 4:25:47 AM6/29/13
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: susan
Type: Bug | Status: assigned
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by susan):

https://github.com/django/django/pull/1314 PR is here.

--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:16>

Django

unread,
Oct 9, 2013, 12:19:53 PM10/9/13
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+------------------------------------
Reporter: anonymous | Owner: susan
Type: Bug | Status: assigned
Component: HTTP handling | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by timo):

* easy: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:17>

Django

unread,
Nov 3, 2013, 6:43:44 PM11/3/13
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+----------------------------------------
Reporter: anonymous | Owner: unaizalakain
Type: Bug | Status: assigned
Component: HTTP handling | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+----------------------------------------
Changes (by unaizalakain):

* owner: susan => unaizalakain


* needs_better_patch: 1 => 0

* version: 1.4 => master


Comment:

Enhanced docs, all test passing plus correct handling of leading slashes
by `WSGIRequest`.

--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:18>

Django

unread,
Jun 7, 2014, 9:02:52 AM6/7/14
to django-...@googlegroups.com
#18314: request.build_absolute_uri() functions incorrectly when the path starts
with //
-------------------------------+----------------------------------------
Reporter: anonymous | Owner: unaizalakain
Type: Bug | Status: closed

Component: HTTP handling | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+----------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"11284a63d48c84f1d60b5686d55cf8a9f8d64422"]:
{{{
#!CommitTicketReference repository=""
revision="11284a63d48c84f1d60b5686d55cf8a9f8d64422"
Fixed #18314 -- Corrected request.build_absolute_uri() handling of paths
starting with //

``HttpRequest.build_absolute_uri()`` now correctly handles paths starting
with ``//``.
``WSGIRequest`` now doesn't remove all the leading slashes either,
because ``http://test/server`` and http://test//server`` aren't the same
thing
(RFC2396).

Thanks to SmileyChris for the initial patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:19>

Reply all
Reply to author
Forward
0 new messages