--
Ticket URL: <https://code.djangoproject.com/ticket/18314>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* 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>
* owner: nobody => yoyoma
--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:2>
* 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>
* status: closed => reopened
* resolution: fixed =>
Comment:
Pardon my resolving of the ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:4>
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:5>
* 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>
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>
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>
* needs_better_patch: 1 => 0
Comment:
Here's a simpler way to do it.
--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:9>
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>
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>
* 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>
* owner: yoyoma => susan
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:14>
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>
Comment (by susan):
https://github.com/django/django/pull/1314 PR is here.
--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:16>
* easy: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/18314#comment:17>
* 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>
* 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>